Formatting the C/C++ files
This commit is contained in:
@@ -1,14 +1,13 @@
|
|||||||
//BSP mapping functions
|
// BSP mapping functions
|
||||||
|
|
||||||
#include <IRQ.h>
|
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
|
#include "I2C_Wrapper.hpp"
|
||||||
|
#include "Model_Config.h"
|
||||||
|
#include "Pins.h"
|
||||||
#include "Setup.h"
|
#include "Setup.h"
|
||||||
#include "history.hpp"
|
#include "history.hpp"
|
||||||
#include "Pins.h"
|
|
||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
#include "history.hpp"
|
#include <IRQ.h>
|
||||||
#include "Model_Config.h"
|
|
||||||
#include "I2C_Wrapper.hpp"
|
|
||||||
volatile uint16_t PWMSafetyTimer = 0;
|
volatile uint16_t PWMSafetyTimer = 0;
|
||||||
volatile uint8_t pendingPWM = 0;
|
volatile uint8_t pendingPWM = 0;
|
||||||
|
|
||||||
@@ -16,20 +15,18 @@ const uint16_t powerPWM = 255;
|
|||||||
static const uint8_t holdoffTicks = 14; // delay of 8 ms
|
static const uint8_t holdoffTicks = 14; // delay of 8 ms
|
||||||
static const uint8_t tempMeasureTicks = 14;
|
static const uint8_t tempMeasureTicks = 14;
|
||||||
|
|
||||||
uint16_t totalPWM; //htim2.Init.Period, the full PWM cycle
|
uint16_t totalPWM; // htim2.Init.Period, the full PWM cycle
|
||||||
|
|
||||||
static bool fastPWM;
|
static bool fastPWM;
|
||||||
|
|
||||||
//2 second filter (ADC is PID_TIM_HZ Hz)
|
// 2 second filter (ADC is PID_TIM_HZ Hz)
|
||||||
history<uint16_t, PID_TIM_HZ> rawTempFilter = { { 0 }, 0, 0 };
|
history<uint16_t, PID_TIM_HZ> rawTempFilter = {{0}, 0, 0};
|
||||||
void resetWatchdog() {
|
void resetWatchdog() { HAL_IWDG_Refresh(&hiwdg); }
|
||||||
HAL_IWDG_Refresh(&hiwdg);
|
|
||||||
}
|
|
||||||
#ifdef TEMP_NTC
|
#ifdef TEMP_NTC
|
||||||
//Lookup table for the NTC
|
// Lookup table for the NTC
|
||||||
//Stored as ADCReading,Temp in degC
|
// Stored as ADCReading,Temp in degC
|
||||||
static const uint16_t NTCHandleLookup[] = {
|
static const uint16_t NTCHandleLookup[] = {
|
||||||
//ADC Reading , Temp in C
|
// ADC Reading , Temp in C
|
||||||
29189, 0, //
|
29189, 0, //
|
||||||
29014, 1, //
|
29014, 1, //
|
||||||
28832, 2, //
|
28832, 2, //
|
||||||
@@ -91,14 +88,14 @@ static const uint16_t NTCHandleLookup[] = {
|
|||||||
// 11874, 58, //
|
// 11874, 58, //
|
||||||
// 11580, 59, //
|
// 11580, 59, //
|
||||||
// 11292, 60, //
|
// 11292, 60, //
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint16_t getHandleTemperature() {
|
uint16_t getHandleTemperature() {
|
||||||
#ifdef TEMP_NTC
|
#ifdef TEMP_NTC
|
||||||
//TS80P uses 100k NTC resistors instead
|
// TS80P uses 100k NTC resistors instead
|
||||||
//NTCG104EF104FT1X from TDK
|
// NTCG104EF104FT1X from TDK
|
||||||
//For now not doing interpolation
|
// For now not doing interpolation
|
||||||
int32_t result = getADC(0);
|
int32_t result = getADC(0);
|
||||||
for (uint32_t i = 0; i < (sizeof(NTCHandleLookup) / (2 * sizeof(uint16_t))); i++) {
|
for (uint32_t i = 0; i < (sizeof(NTCHandleLookup) / (2 * sizeof(uint16_t))); i++) {
|
||||||
if (result > NTCHandleLookup[(i * 2) + 0]) {
|
if (result > NTCHandleLookup[(i * 2) + 0]) {
|
||||||
@@ -128,9 +125,9 @@ uint16_t getHandleTemperature() {
|
|||||||
uint16_t getTipInstantTemperature() {
|
uint16_t getTipInstantTemperature() {
|
||||||
uint16_t sum = 0; // 12 bit readings * 8 -> 15 bits
|
uint16_t sum = 0; // 12 bit readings * 8 -> 15 bits
|
||||||
uint16_t readings[8];
|
uint16_t readings[8];
|
||||||
//Looking to reject the highest outlier readings.
|
// Looking to reject the highest outlier readings.
|
||||||
//As on some hardware these samples can run into the op-amp recovery time
|
// As on some hardware these samples can run into the op-amp recovery time
|
||||||
//Once this time is up the signal stabilises quickly, so no need to reject minimums
|
// Once this time is up the signal stabilises quickly, so no need to reject minimums
|
||||||
readings[0] = hadc1.Instance->JDR1;
|
readings[0] = hadc1.Instance->JDR1;
|
||||||
readings[1] = hadc1.Instance->JDR2;
|
readings[1] = hadc1.Instance->JDR2;
|
||||||
readings[2] = hadc1.Instance->JDR3;
|
readings[2] = hadc1.Instance->JDR3;
|
||||||
@@ -289,7 +286,7 @@ void unstick_I2C() {
|
|||||||
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
while (GPIO_PIN_SET != HAL_GPIO_ReadPin(SDA_GPIO_Port, SDA_Pin)) {
|
while (GPIO_PIN_SET != HAL_GPIO_ReadPin(SDA_GPIO_Port, SDA_Pin)) {
|
||||||
//Move clock to release I2C
|
// Move clock to release I2C
|
||||||
HAL_GPIO_WritePin(SCL_GPIO_Port, SCL_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(SCL_GPIO_Port, SCL_Pin, GPIO_PIN_RESET);
|
||||||
asm("nop");
|
asm("nop");
|
||||||
asm("nop");
|
asm("nop");
|
||||||
@@ -333,21 +330,11 @@ void unstick_I2C() {
|
|||||||
HAL_I2C_Init(&hi2c1);
|
HAL_I2C_Init(&hi2c1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getButtonA() {
|
uint8_t getButtonA() { return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ? 1 : 0; }
|
||||||
return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ? 1 : 0;
|
uint8_t getButtonB() { return HAL_GPIO_ReadPin(KEY_B_GPIO_Port, KEY_B_Pin) == GPIO_PIN_RESET ? 1 : 0; }
|
||||||
}
|
|
||||||
uint8_t getButtonB() {
|
|
||||||
return HAL_GPIO_ReadPin(KEY_B_GPIO_Port, KEY_B_Pin) == GPIO_PIN_RESET ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BSPInit(void) {
|
void BSPInit(void) { switchToFastPWM(); }
|
||||||
switchToFastPWM();
|
|
||||||
}
|
|
||||||
|
|
||||||
void reboot() {
|
void reboot() { NVIC_SystemReset(); }
|
||||||
NVIC_SystemReset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void delay_ms(uint16_t count) {
|
void delay_ms(uint16_t count) { HAL_Delay(count); }
|
||||||
HAL_Delay(count);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -12,11 +12,11 @@
|
|||||||
* An array of all of the desired voltages & minimum currents in preferred order
|
* An array of all of the desired voltages & minimum currents in preferred order
|
||||||
*/
|
*/
|
||||||
const uint16_t USB_PD_Desired_Levels[] = {
|
const uint16_t USB_PD_Desired_Levels[] = {
|
||||||
//mV desired input, mA minimum required current
|
// mV desired input, mA minimum required current
|
||||||
12000, 2400, //12V @ 2.4A
|
12000, 2400, // 12V @ 2.4A
|
||||||
9000, 2000, //9V @ 2A
|
9000, 2000, // 9V @ 2A
|
||||||
5000, 100, //5V @ whatever
|
5000, 100, // 5V @ whatever
|
||||||
|
|
||||||
};
|
};
|
||||||
const uint8_t USB_PD_Desired_Levels_Len = 3;
|
const uint8_t USB_PD_Desired_Levels_Len = 3;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,13 +17,11 @@ void FRToSI2C::CpltCallback() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, uint16_t Size) {
|
||||||
uint8_t *pData, uint16_t Size) {
|
|
||||||
|
|
||||||
if (!lock())
|
if (!lock())
|
||||||
return false;
|
return false;
|
||||||
if (HAL_I2C_Mem_Read(&hi2c1, DevAddress, MemAddress, I2C_MEMADD_SIZE_8BIT,
|
if (HAL_I2C_Mem_Read(&hi2c1, DevAddress, MemAddress, I2C_MEMADD_SIZE_8BIT, pData, Size, 500) != HAL_OK) {
|
||||||
pData, Size, 500) != HAL_OK) {
|
|
||||||
|
|
||||||
I2C_Unstick();
|
I2C_Unstick();
|
||||||
unlock();
|
unlock();
|
||||||
@@ -33,22 +31,18 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
unlock();
|
unlock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) {
|
bool FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) { return Mem_Write(address, reg, &data, 1); }
|
||||||
return Mem_Write(address, reg, &data, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) {
|
uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) {
|
||||||
uint8_t tx_data[1];
|
uint8_t tx_data[1];
|
||||||
Mem_Read(add, reg, tx_data, 1);
|
Mem_Read(add, reg, tx_data, 1);
|
||||||
return tx_data[0];
|
return tx_data[0];
|
||||||
}
|
}
|
||||||
bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, uint16_t Size) {
|
||||||
uint8_t *pData, uint16_t Size) {
|
|
||||||
|
|
||||||
if (!lock())
|
if (!lock())
|
||||||
return false;
|
return false;
|
||||||
if (HAL_I2C_Mem_Write(&hi2c1, DevAddress, MemAddress, I2C_MEMADD_SIZE_8BIT,
|
if (HAL_I2C_Mem_Write(&hi2c1, DevAddress, MemAddress, I2C_MEMADD_SIZE_8BIT, pData, Size, 500) != HAL_OK) {
|
||||||
pData, Size, 500) != HAL_OK) {
|
|
||||||
|
|
||||||
I2C_Unstick();
|
I2C_Unstick();
|
||||||
unlock();
|
unlock();
|
||||||
@@ -62,8 +56,7 @@ bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
||||||
if (!lock())
|
if (!lock())
|
||||||
return false;
|
return false;
|
||||||
if (HAL_I2C_Master_Transmit_DMA(&hi2c1, DevAddress, pData, Size)
|
if (HAL_I2C_Master_Transmit_DMA(&hi2c1, DevAddress, pData, Size) != HAL_OK) {
|
||||||
!= HAL_OK) {
|
|
||||||
I2C_Unstick();
|
I2C_Unstick();
|
||||||
unlock();
|
unlock();
|
||||||
return false;
|
return false;
|
||||||
@@ -75,29 +68,20 @@ bool FRToSI2C::probe(uint16_t DevAddress) {
|
|||||||
if (!lock())
|
if (!lock())
|
||||||
return false;
|
return false;
|
||||||
uint8_t buffer[1];
|
uint8_t buffer[1];
|
||||||
bool worked = HAL_I2C_Mem_Read(&hi2c1, DevAddress, 0x0F,
|
bool worked = HAL_I2C_Mem_Read(&hi2c1, DevAddress, 0x0F, I2C_MEMADD_SIZE_8BIT, buffer, 1, 1000) == HAL_OK;
|
||||||
I2C_MEMADD_SIZE_8BIT, buffer, 1, 1000) == HAL_OK;
|
|
||||||
unlock();
|
unlock();
|
||||||
return worked;
|
return worked;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FRToSI2C::I2C_Unstick() {
|
void FRToSI2C::I2C_Unstick() { unstick_I2C(); }
|
||||||
unstick_I2C();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FRToSI2C::unlock() {
|
void FRToSI2C::unlock() { xSemaphoreGive(I2CSemaphore); }
|
||||||
xSemaphoreGive(I2CSemaphore);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FRToSI2C::lock() {
|
bool FRToSI2C::lock() { return xSemaphoreTake(I2CSemaphore, (TickType_t)50) == pdTRUE; }
|
||||||
return xSemaphoreTake(I2CSemaphore, (TickType_t)50) == pdTRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FRToSI2C::writeRegistersBulk(const uint8_t address,
|
bool FRToSI2C::writeRegistersBulk(const uint8_t address, const I2C_REG *registers, const uint8_t registersLength) {
|
||||||
const I2C_REG *registers, const uint8_t registersLength) {
|
|
||||||
for (int index = 0; index < registersLength; index++) {
|
for (int index = 0; index < registersLength; index++) {
|
||||||
if (!I2C_RegisterWrite(address, registers[index].reg,
|
if (!I2C_RegisterWrite(address, registers[index].reg, registers[index].val)) {
|
||||||
registers[index].val)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (registers[index].pause_ms)
|
if (registers[index].pause_ms)
|
||||||
|
|||||||
@@ -16,34 +16,19 @@ void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc) {
|
|||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||||
if (hadc == &hadc1) {
|
if (hadc == &hadc1) {
|
||||||
if (pidTaskNotification) {
|
if (pidTaskNotification) {
|
||||||
vTaskNotifyGiveFromISR(pidTaskNotification,
|
vTaskNotifyGiveFromISR(pidTaskNotification, &xHigherPriorityTaskWoken);
|
||||||
&xHigherPriorityTaskWoken);
|
|
||||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) { FRToSI2C::CpltCallback(); }
|
||||||
FRToSI2C::CpltCallback();
|
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) { FRToSI2C::CpltCallback(); }
|
||||||
}
|
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) { FRToSI2C::CpltCallback(); }
|
||||||
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c __unused) { FRToSI2C::CpltCallback(); }
|
||||||
FRToSI2C::CpltCallback();
|
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c __unused) { FRToSI2C::CpltCallback(); }
|
||||||
}
|
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) { FRToSI2C::CpltCallback(); }
|
||||||
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
|
||||||
FRToSI2C::CpltCallback();
|
|
||||||
}
|
|
||||||
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c __unused) {
|
|
||||||
|
|
||||||
FRToSI2C::CpltCallback();
|
|
||||||
}
|
|
||||||
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
|
||||||
|
|
||||||
FRToSI2C::CpltCallback();
|
|
||||||
}
|
|
||||||
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
|
||||||
FRToSI2C::CpltCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
|
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
|
||||||
(void) GPIO_Pin;
|
(void)GPIO_Pin;
|
||||||
InterruptHandler::irqCallback();
|
InterruptHandler::irqCallback();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "BSP_Power.h"
|
#include "BSP_Power.h"
|
||||||
|
#include "Model_Config.h"
|
||||||
|
#include "Pins.h"
|
||||||
#include "QC3.h"
|
#include "QC3.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "Pins.h"
|
|
||||||
#include "fusbpd.h"
|
#include "fusbpd.h"
|
||||||
#include "Model_Config.h"
|
|
||||||
#include "policy_engine.h"
|
|
||||||
#include "int_n.h"
|
#include "int_n.h"
|
||||||
|
#include "policy_engine.h"
|
||||||
bool FUSB302_present = false;
|
bool FUSB302_present = false;
|
||||||
|
|
||||||
void power_check() {
|
void power_check() {
|
||||||
#ifdef POW_PD
|
#ifdef POW_PD
|
||||||
if (FUSB302_present) {
|
if (FUSB302_present) {
|
||||||
//Cant start QC until either PD works or fails
|
// Cant start QC until either PD works or fails
|
||||||
if (PolicyEngine::setupCompleteOrTimedOut() == false) {
|
if (PolicyEngine::setupCompleteOrTimedOut() == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -46,4 +46,3 @@ bool getIsPoweredByDCIN() {
|
|||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
* Author: Ralim
|
* Author: Ralim
|
||||||
*/
|
*/
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
|
#include "Model_Config.h"
|
||||||
#include "Pins.h"
|
#include "Pins.h"
|
||||||
#include "QC3.h"
|
#include "QC3.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "stm32f1xx_hal.h"
|
#include "stm32f1xx_hal.h"
|
||||||
#include "Model_Config.h"
|
|
||||||
#ifdef POW_QC
|
#ifdef POW_QC
|
||||||
void QC_DPlusZero_Six() {
|
void QC_DPlusZero_Six() {
|
||||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); // pull down D+
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); // pull down D+
|
||||||
@@ -66,9 +66,7 @@ void QC_Post_Probe_En() {
|
|||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t QC_DM_PulledDown() {
|
uint8_t QC_DM_PulledDown() { return HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET ? 1 : 0; }
|
||||||
return HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET ? 1 : 0;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
void QC_resync() {
|
void QC_resync() {
|
||||||
#ifdef POW_QC
|
#ifdef POW_QC
|
||||||
|
|||||||
@@ -75,8 +75,7 @@ void SystemClock_Config(void) {
|
|||||||
|
|
||||||
/**Initializes the CPU, AHB and APB busses clocks
|
/**Initializes the CPU, AHB and APB busses clocks
|
||||||
*/
|
*/
|
||||||
RCC_OscInitStruct.OscillatorType =
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI;
|
||||||
RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI;
|
|
||||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
RCC_OscInitStruct.HSICalibrationValue = 16;
|
RCC_OscInitStruct.HSICalibrationValue = 16;
|
||||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||||
@@ -87,20 +86,17 @@ void SystemClock_Config(void) {
|
|||||||
|
|
||||||
/**Initializes the CPU, AHB and APB busses clocks
|
/**Initializes the CPU, AHB and APB busses clocks
|
||||||
*/
|
*/
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||||
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV16; // TIM
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV16; // TIM
|
||||||
// 2,3,4,5,6,7,12,13,14
|
// 2,3,4,5,6,7,12,13,14
|
||||||
RCC_ClkInitStruct.APB2CLKDivider =
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // 64 mhz to some peripherals and adc
|
||||||
RCC_HCLK_DIV1; // 64 mhz to some peripherals and adc
|
|
||||||
|
|
||||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
|
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
|
||||||
|
|
||||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
|
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
|
||||||
PeriphClkInit.AdcClockSelection =
|
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; // 6 or 8 are the only non overclocked options
|
||||||
RCC_ADCPCLK2_DIV6; // 6 or 8 are the only non overclocked options
|
|
||||||
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
|
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
|
||||||
|
|
||||||
/**Configure the Systick interrupt time
|
/**Configure the Systick interrupt time
|
||||||
@@ -269,7 +265,7 @@ static void MX_TIM3_Init(void) {
|
|||||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
htim3.Init.Period = 100; // 5 Khz PWM freq
|
htim3.Init.Period = 100; // 5 Khz PWM freq
|
||||||
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 4mhz before div
|
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 4mhz before div
|
||||||
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; //Preload the ARR register (though we dont use this)
|
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; // Preload the ARR register (though we dont use this)
|
||||||
HAL_TIM_Base_Init(&htim3);
|
HAL_TIM_Base_Init(&htim3);
|
||||||
|
|
||||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
@@ -284,7 +280,7 @@ static void MX_TIM3_Init(void) {
|
|||||||
HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig);
|
HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig);
|
||||||
|
|
||||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||||
sConfigOC.Pulse = 50; //50% duty cycle, that is AC coupled through the cap
|
sConfigOC.Pulse = 50; // 50% duty cycle, that is AC coupled through the cap
|
||||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||||
HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, PWM_Out_CHANNEL);
|
HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, PWM_Out_CHANNEL);
|
||||||
@@ -296,12 +292,11 @@ static void MX_TIM3_Init(void) {
|
|||||||
*/
|
*/
|
||||||
GPIO_InitStruct.Pin = PWM_Out_Pin;
|
GPIO_InitStruct.Pin = PWM_Out_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; //We would like sharp rising edges
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; // We would like sharp rising edges
|
||||||
HAL_GPIO_Init(PWM_Out_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(PWM_Out_GPIO_Port, &GPIO_InitStruct);
|
||||||
#ifdef MODEL_TS100
|
#ifdef MODEL_TS100
|
||||||
// Remap TIM3_CH1 to be on PB4
|
// Remap TIM3_CH1 to be on PB4
|
||||||
__HAL_AFIO_REMAP_TIM3_PARTIAL()
|
__HAL_AFIO_REMAP_TIM3_PARTIAL();
|
||||||
;
|
|
||||||
#else
|
#else
|
||||||
// No re-map required
|
// No re-map required
|
||||||
#endif
|
#endif
|
||||||
@@ -346,7 +341,7 @@ static void MX_TIM2_Init(void) {
|
|||||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||||
// dummy value, will be reconfigured by BSPInit() in the BSP.cpp
|
// dummy value, will be reconfigured by BSPInit() in the BSP.cpp
|
||||||
sConfigOC.Pulse = 255 + 13 * 2; // 13 -> Delay of 7 ms
|
sConfigOC.Pulse = 255 + 13 * 2; // 13 -> Delay of 7 ms
|
||||||
//255 is the largest time period of the drive signal, and then offset ADC sample to be a bit delayed after this
|
// 255 is the largest time period of the drive signal, and then offset ADC sample to be a bit delayed after this
|
||||||
/*
|
/*
|
||||||
* It takes 4 milliseconds for output to be stable after PWM turns off.
|
* It takes 4 milliseconds for output to be stable after PWM turns off.
|
||||||
* Assume ADC samples in 0.5ms
|
* Assume ADC samples in 0.5ms
|
||||||
@@ -355,7 +350,7 @@ static void MX_TIM2_Init(void) {
|
|||||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||||
HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1);
|
HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1);
|
||||||
sConfigOC.Pulse = 0; //default to entirely off
|
sConfigOC.Pulse = 0; // default to entirely off
|
||||||
HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4);
|
HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4);
|
||||||
|
|
||||||
HAL_TIM_Base_Start_IT(&htim2);
|
HAL_TIM_Base_Start_IT(&htim2);
|
||||||
@@ -370,8 +365,7 @@ static void MX_TIM2_Init(void) {
|
|||||||
*/
|
*/
|
||||||
static void MX_DMA_Init(void) {
|
static void MX_DMA_Init(void) {
|
||||||
/* DMA controller clock enable */
|
/* DMA controller clock enable */
|
||||||
__HAL_RCC_DMA1_CLK_ENABLE()
|
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||||
;
|
|
||||||
|
|
||||||
/* DMA interrupt init */
|
/* DMA interrupt init */
|
||||||
/* DMA1_Channel1_IRQn interrupt configuration */
|
/* DMA1_Channel1_IRQn interrupt configuration */
|
||||||
@@ -399,12 +393,9 @@ static void MX_GPIO_Init(void) {
|
|||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
/* GPIO Ports Clock Enable */
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE()
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
;
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE()
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
;
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE()
|
|
||||||
;
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_RESET);
|
||||||
@@ -414,26 +405,21 @@ static void MX_GPIO_Init(void) {
|
|||||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
/*Configure peripheral I/O remapping */
|
/*Configure peripheral I/O remapping */
|
||||||
__HAL_AFIO_REMAP_PD01_ENABLE()
|
__HAL_AFIO_REMAP_PD01_ENABLE();
|
||||||
;
|
|
||||||
//^ remap XTAL so that pins can be analog (all input buffers off).
|
//^ remap XTAL so that pins can be analog (all input buffers off).
|
||||||
// reduces power consumption
|
// reduces power consumption
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Configure All pins as analog by default
|
* Configure All pins as analog by default
|
||||||
*/
|
*/
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 |
|
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_15;
|
||||||
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 |
|
|
||||||
GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_15;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 |
|
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 |
|
||||||
#ifdef MODEL_TS100
|
#ifdef MODEL_TS100
|
||||||
GPIO_PIN_3 |
|
GPIO_PIN_3 |
|
||||||
#endif
|
#endif
|
||||||
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 |
|
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
|
||||||
GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 |
|
|
||||||
GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
|
|
||||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
#ifdef MODEL_TS100
|
#ifdef MODEL_TS100
|
||||||
@@ -479,7 +465,5 @@ static void MX_GPIO_Init(void) {
|
|||||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
|
||||||
}
|
}
|
||||||
#ifdef USE_FULL_ASSERT
|
#ifdef USE_FULL_ASSERT
|
||||||
void assert_failed(uint8_t* file, uint32_t line){
|
void assert_failed(uint8_t *file, uint32_t line) { asm("bkpt"); }
|
||||||
asm("bkpt");
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -75,10 +75,7 @@
|
|||||||
#define __STM32F1xx_HAL_VERSION_SUB1 (0x01U) /*!< [23:16] sub1 version */
|
#define __STM32F1xx_HAL_VERSION_SUB1 (0x01U) /*!< [23:16] sub1 version */
|
||||||
#define __STM32F1xx_HAL_VERSION_SUB2 (0x03U) /*!< [15:8] sub2 version */
|
#define __STM32F1xx_HAL_VERSION_SUB2 (0x03U) /*!< [15:8] sub2 version */
|
||||||
#define __STM32F1xx_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */
|
#define __STM32F1xx_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */
|
||||||
#define __STM32F1xx_HAL_VERSION ((__STM32F1xx_HAL_VERSION_MAIN << 24)\
|
#define __STM32F1xx_HAL_VERSION ((__STM32F1xx_HAL_VERSION_MAIN << 24) | (__STM32F1xx_HAL_VERSION_SUB1 << 16) | (__STM32F1xx_HAL_VERSION_SUB2 << 8) | (__STM32F1xx_HAL_VERSION_RC))
|
||||||
|(__STM32F1xx_HAL_VERSION_SUB1 << 16)\
|
|
||||||
|(__STM32F1xx_HAL_VERSION_SUB2 << 8 )\
|
|
||||||
|(__STM32F1xx_HAL_VERSION_RC))
|
|
||||||
|
|
||||||
#define IDCODE_DEVID_MASK 0x00000FFFU
|
#define IDCODE_DEVID_MASK 0x00000FFFU
|
||||||
|
|
||||||
@@ -155,14 +152,11 @@ HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT; /* 1KHz */
|
|||||||
* to have correct HAL operation.
|
* to have correct HAL operation.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_Init(void)
|
HAL_StatusTypeDef HAL_Init(void) {
|
||||||
{
|
|
||||||
/* Configure Flash prefetch */
|
/* Configure Flash prefetch */
|
||||||
#if (PREFETCH_ENABLE != 0)
|
#if (PREFETCH_ENABLE != 0)
|
||||||
#if defined(STM32F101x6) || defined(STM32F101xB) || defined(STM32F101xE) || defined(STM32F101xG) || \
|
#if defined(STM32F101x6) || defined(STM32F101xB) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6) || defined(STM32F103xB) \
|
||||||
defined(STM32F102x6) || defined(STM32F102xB) || \
|
|| defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || \
|
|
||||||
defined(STM32F105xC) || defined(STM32F107xC)
|
|
||||||
|
|
||||||
/* Prefetch buffer is not available on value line devices */
|
/* Prefetch buffer is not available on value line devices */
|
||||||
__HAL_FLASH_PREFETCH_BUFFER_ENABLE();
|
__HAL_FLASH_PREFETCH_BUFFER_ENABLE();
|
||||||
@@ -188,8 +182,7 @@ HAL_StatusTypeDef HAL_Init(void)
|
|||||||
* @note This function is optional.
|
* @note This function is optional.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_DeInit(void)
|
HAL_StatusTypeDef HAL_DeInit(void) {
|
||||||
{
|
|
||||||
/* Reset of all peripherals */
|
/* Reset of all peripherals */
|
||||||
__HAL_RCC_APB1_FORCE_RESET();
|
__HAL_RCC_APB1_FORCE_RESET();
|
||||||
__HAL_RCC_APB1_RELEASE_RESET();
|
__HAL_RCC_APB1_RELEASE_RESET();
|
||||||
@@ -213,8 +206,7 @@ HAL_StatusTypeDef HAL_DeInit(void)
|
|||||||
* @brief Initialize the MSP.
|
* @brief Initialize the MSP.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_MspInit(void)
|
__weak void HAL_MspInit(void) {
|
||||||
{
|
|
||||||
/* NOTE : This function should not be modified, when the callback is needed,
|
/* NOTE : This function should not be modified, when the callback is needed,
|
||||||
the HAL_MspInit could be implemented in the user file
|
the HAL_MspInit could be implemented in the user file
|
||||||
*/
|
*/
|
||||||
@@ -224,8 +216,7 @@ __weak void HAL_MspInit(void)
|
|||||||
* @brief DeInitializes the MSP.
|
* @brief DeInitializes the MSP.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_MspDeInit(void)
|
__weak void HAL_MspDeInit(void) {
|
||||||
{
|
|
||||||
/* NOTE : This function should not be modified, when the callback is needed,
|
/* NOTE : This function should not be modified, when the callback is needed,
|
||||||
the HAL_MspDeInit could be implemented in the user file
|
the HAL_MspDeInit could be implemented in the user file
|
||||||
*/
|
*/
|
||||||
@@ -247,22 +238,17 @@ __weak void HAL_MspDeInit(void)
|
|||||||
* @param TickPriority Tick interrupt priority.
|
* @param TickPriority Tick interrupt priority.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
|
||||||
{
|
|
||||||
/* Configure the SysTick to have interrupt in 1ms time basis*/
|
/* Configure the SysTick to have interrupt in 1ms time basis*/
|
||||||
if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) > 0U)
|
if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) > 0U) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Configure the SysTick IRQ priority */
|
/* Configure the SysTick IRQ priority */
|
||||||
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
|
if (TickPriority < (1UL << __NVIC_PRIO_BITS)) {
|
||||||
{
|
|
||||||
HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
|
HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
|
||||||
uwTickPrio = TickPriority;
|
uwTickPrio = TickPriority;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,10 +292,7 @@ __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
|||||||
* implementations in user file.
|
* implementations in user file.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_IncTick(void)
|
__weak void HAL_IncTick(void) { uwTick += uwTickFreq; }
|
||||||
{
|
|
||||||
uwTick += uwTickFreq;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Provides a tick value in millisecond.
|
* @brief Provides a tick value in millisecond.
|
||||||
@@ -317,31 +300,23 @@ __weak void HAL_IncTick(void)
|
|||||||
* implementations in user file.
|
* implementations in user file.
|
||||||
* @retval tick value
|
* @retval tick value
|
||||||
*/
|
*/
|
||||||
__weak uint32_t HAL_GetTick(void)
|
__weak uint32_t HAL_GetTick(void) { return uwTick; }
|
||||||
{
|
|
||||||
return uwTick;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function returns a tick priority.
|
* @brief This function returns a tick priority.
|
||||||
* @retval tick priority
|
* @retval tick priority
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_GetTickPrio(void)
|
uint32_t HAL_GetTickPrio(void) { return uwTickPrio; }
|
||||||
{
|
|
||||||
return uwTickPrio;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set new tick Freq.
|
* @brief Set new tick Freq.
|
||||||
* @retval Status
|
* @retval Status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
|
HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
assert_param(IS_TICKFREQ(Freq));
|
assert_param(IS_TICKFREQ(Freq));
|
||||||
|
|
||||||
if (uwTickFreq != Freq)
|
if (uwTickFreq != Freq) {
|
||||||
{
|
|
||||||
uwTickFreq = Freq;
|
uwTickFreq = Freq;
|
||||||
|
|
||||||
/* Apply the new tick Freq */
|
/* Apply the new tick Freq */
|
||||||
@@ -355,10 +330,7 @@ HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
|
|||||||
* @brief Return tick frequency.
|
* @brief Return tick frequency.
|
||||||
* @retval tick period in Hz
|
* @retval tick period in Hz
|
||||||
*/
|
*/
|
||||||
HAL_TickFreqTypeDef HAL_GetTickFreq(void)
|
HAL_TickFreqTypeDef HAL_GetTickFreq(void) { return uwTickFreq; }
|
||||||
{
|
|
||||||
return uwTickFreq;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function provides minimum delay (in milliseconds) based
|
* @brief This function provides minimum delay (in milliseconds) based
|
||||||
@@ -371,20 +343,16 @@ HAL_TickFreqTypeDef HAL_GetTickFreq(void)
|
|||||||
* @param Delay specifies the delay time length, in milliseconds.
|
* @param Delay specifies the delay time length, in milliseconds.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_Delay(uint32_t Delay)
|
__weak void HAL_Delay(uint32_t Delay) {
|
||||||
{
|
|
||||||
uint32_t tickstart = HAL_GetTick();
|
uint32_t tickstart = HAL_GetTick();
|
||||||
uint32_t wait = Delay;
|
uint32_t wait = Delay;
|
||||||
|
|
||||||
/* Add a freq to guarantee minimum wait */
|
/* Add a freq to guarantee minimum wait */
|
||||||
if (wait < HAL_MAX_DELAY)
|
if (wait < HAL_MAX_DELAY) {
|
||||||
{
|
|
||||||
wait += (uint32_t)(uwTickFreq);
|
wait += (uint32_t)(uwTickFreq);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((HAL_GetTick() - tickstart) < wait)
|
while ((HAL_GetTick() - tickstart) < wait) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -397,8 +365,7 @@ __weak void HAL_Delay(uint32_t Delay)
|
|||||||
* implementations in user file.
|
* implementations in user file.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_SuspendTick(void)
|
__weak void HAL_SuspendTick(void) {
|
||||||
{
|
|
||||||
/* Disable SysTick Interrupt */
|
/* Disable SysTick Interrupt */
|
||||||
CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
|
CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
|
||||||
}
|
}
|
||||||
@@ -413,8 +380,7 @@ __weak void HAL_SuspendTick(void)
|
|||||||
* implementations in user file.
|
* implementations in user file.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_ResumeTick(void)
|
__weak void HAL_ResumeTick(void) {
|
||||||
{
|
|
||||||
/* Enable SysTick Interrupt */
|
/* Enable SysTick Interrupt */
|
||||||
SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
|
SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
|
||||||
}
|
}
|
||||||
@@ -423,10 +389,7 @@ __weak void HAL_ResumeTick(void)
|
|||||||
* @brief Returns the HAL revision
|
* @brief Returns the HAL revision
|
||||||
* @retval version 0xXYZR (8bits for each decimal, R for RC)
|
* @retval version 0xXYZR (8bits for each decimal, R for RC)
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_GetHalVersion(void)
|
uint32_t HAL_GetHalVersion(void) { return __STM32F1xx_HAL_VERSION; }
|
||||||
{
|
|
||||||
return __STM32F1xx_HAL_VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the device revision identifier.
|
* @brief Returns the device revision identifier.
|
||||||
@@ -439,10 +402,7 @@ uint32_t HAL_GetHalVersion(void)
|
|||||||
* Refer to errata sheet of these devices for more details.
|
* Refer to errata sheet of these devices for more details.
|
||||||
* @retval Device revision identifier
|
* @retval Device revision identifier
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_GetREVID(void)
|
uint32_t HAL_GetREVID(void) { return ((DBGMCU->IDCODE) >> DBGMCU_IDCODE_REV_ID_Pos); }
|
||||||
{
|
|
||||||
return ((DBGMCU->IDCODE) >> DBGMCU_IDCODE_REV_ID_Pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the device identifier.
|
* @brief Returns the device identifier.
|
||||||
@@ -455,19 +415,13 @@ uint32_t HAL_GetREVID(void)
|
|||||||
* Refer to errata sheet of these devices for more details.
|
* Refer to errata sheet of these devices for more details.
|
||||||
* @retval Device identifier
|
* @retval Device identifier
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_GetDEVID(void)
|
uint32_t HAL_GetDEVID(void) { return ((DBGMCU->IDCODE) & IDCODE_DEVID_MASK); }
|
||||||
{
|
|
||||||
return ((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enable the Debug Module during SLEEP mode
|
* @brief Enable the Debug Module during SLEEP mode
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_DBGMCU_EnableDBGSleepMode(void)
|
void HAL_DBGMCU_EnableDBGSleepMode(void) { SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); }
|
||||||
{
|
|
||||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Disable the Debug Module during SLEEP mode
|
* @brief Disable the Debug Module during SLEEP mode
|
||||||
@@ -480,10 +434,7 @@ void HAL_DBGMCU_EnableDBGSleepMode(void)
|
|||||||
* Refer to errata sheet of these devices for more details.
|
* Refer to errata sheet of these devices for more details.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_DBGMCU_DisableDBGSleepMode(void)
|
void HAL_DBGMCU_DisableDBGSleepMode(void) { CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); }
|
||||||
{
|
|
||||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enable the Debug Module during STOP mode
|
* @brief Enable the Debug Module during STOP mode
|
||||||
@@ -510,10 +461,7 @@ void HAL_DBGMCU_DisableDBGSleepMode(void)
|
|||||||
* Refer to errata sheet of these devices for more details.
|
* Refer to errata sheet of these devices for more details.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_DBGMCU_EnableDBGStopMode(void)
|
void HAL_DBGMCU_EnableDBGStopMode(void) { SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); }
|
||||||
{
|
|
||||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Disable the Debug Module during STOP mode
|
* @brief Disable the Debug Module during STOP mode
|
||||||
@@ -526,10 +474,7 @@ void HAL_DBGMCU_EnableDBGStopMode(void)
|
|||||||
* Refer to errata sheet of these devices for more details.
|
* Refer to errata sheet of these devices for more details.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_DBGMCU_DisableDBGStopMode(void)
|
void HAL_DBGMCU_DisableDBGStopMode(void) { CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); }
|
||||||
{
|
|
||||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enable the Debug Module during STANDBY mode
|
* @brief Enable the Debug Module during STANDBY mode
|
||||||
@@ -542,10 +487,7 @@ void HAL_DBGMCU_DisableDBGStopMode(void)
|
|||||||
* Refer to errata sheet of these devices for more details.
|
* Refer to errata sheet of these devices for more details.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_DBGMCU_EnableDBGStandbyMode(void)
|
void HAL_DBGMCU_EnableDBGStandbyMode(void) { SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); }
|
||||||
{
|
|
||||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Disable the Debug Module during STANDBY mode
|
* @brief Disable the Debug Module during STANDBY mode
|
||||||
@@ -558,18 +500,14 @@ void HAL_DBGMCU_EnableDBGStandbyMode(void)
|
|||||||
* Refer to errata sheet of these devices for more details.
|
* Refer to errata sheet of these devices for more details.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_DBGMCU_DisableDBGStandbyMode(void)
|
void HAL_DBGMCU_DisableDBGStandbyMode(void) { CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); }
|
||||||
{
|
|
||||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the unique device identifier (UID based on 96 bits)
|
* @brief Return the unique device identifier (UID based on 96 bits)
|
||||||
* @param UID pointer to 3 words array.
|
* @param UID pointer to 3 words array.
|
||||||
* @retval Device identifier
|
* @retval Device identifier
|
||||||
*/
|
*/
|
||||||
void HAL_GetUID(uint32_t *UID)
|
void HAL_GetUID(uint32_t *UID) {
|
||||||
{
|
|
||||||
UID[0] = (uint32_t)(READ_REG(*((uint32_t *)UID_BASE)));
|
UID[0] = (uint32_t)(READ_REG(*((uint32_t *)UID_BASE)));
|
||||||
UID[1] = (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
|
UID[1] = (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
|
||||||
UID[2] = (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
|
UID[2] = (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -71,24 +71,24 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Delay for ADC calibration: */
|
/* Delay for ADC calibration: */
|
||||||
/* Hardware prerequisite before starting a calibration: the ADC must have */
|
/* Hardware prerequisite before starting a calibration: the ADC must have */
|
||||||
/* been in power-on state for at least two ADC clock cycles. */
|
/* been in power-on state for at least two ADC clock cycles. */
|
||||||
/* Unit: ADC clock cycles */
|
/* Unit: ADC clock cycles */
|
||||||
#define ADC_PRECALIBRATION_DELAY_ADCCLOCKCYCLES 2U
|
#define ADC_PRECALIBRATION_DELAY_ADCCLOCKCYCLES 2U
|
||||||
|
|
||||||
/* Timeout value for ADC calibration */
|
/* Timeout value for ADC calibration */
|
||||||
/* Value defined to be higher than worst cases: low clocks freq, */
|
/* Value defined to be higher than worst cases: low clocks freq, */
|
||||||
/* maximum prescaler. */
|
/* maximum prescaler. */
|
||||||
/* Ex of profile low frequency : Clock source at 0.1 MHz, ADC clock */
|
/* Ex of profile low frequency : Clock source at 0.1 MHz, ADC clock */
|
||||||
/* prescaler 4, sampling time 12.5 ADC clock cycles, resolution 12 bits. */
|
/* prescaler 4, sampling time 12.5 ADC clock cycles, resolution 12 bits. */
|
||||||
/* Unit: ms */
|
/* Unit: ms */
|
||||||
#define ADC_CALIBRATION_TIMEOUT 10U
|
#define ADC_CALIBRATION_TIMEOUT 10U
|
||||||
|
|
||||||
/* Delay for temperature sensor stabilization time. */
|
/* Delay for temperature sensor stabilization time. */
|
||||||
/* Maximum delay is 10us (refer to device datasheet, parameter tSTART). */
|
/* Maximum delay is 10us (refer to device datasheet, parameter tSTART). */
|
||||||
/* Unit: us */
|
/* Unit: us */
|
||||||
#define ADC_TEMPSENSOR_DELAY_US 10U
|
#define ADC_TEMPSENSOR_DELAY_US 10U
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -139,8 +139,7 @@
|
|||||||
* @param hadc: ADC handle
|
* @param hadc: ADC handle
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
|
HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||||
uint32_t tickstart;
|
uint32_t tickstart;
|
||||||
__IO uint32_t wait_loop_index = 0U;
|
__IO uint32_t wait_loop_index = 0U;
|
||||||
@@ -159,22 +158,16 @@ HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
|
|||||||
tmp_hal_status = ADC_ConversionStop_Disable(hadc);
|
tmp_hal_status = ADC_ConversionStop_Disable(hadc);
|
||||||
|
|
||||||
/* Check if ADC is effectively disabled */
|
/* Check if ADC is effectively disabled */
|
||||||
if (tmp_hal_status == HAL_OK)
|
if (tmp_hal_status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Set ADC state */
|
/* Set ADC state */
|
||||||
ADC_STATE_CLR_SET(hadc->State,
|
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, HAL_ADC_STATE_BUSY_INTERNAL);
|
||||||
HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
|
|
||||||
HAL_ADC_STATE_BUSY_INTERNAL);
|
|
||||||
|
|
||||||
/* Hardware prerequisite: delay before starting the calibration. */
|
/* Hardware prerequisite: delay before starting the calibration. */
|
||||||
/* - Computation of CPU clock cycles corresponding to ADC clock cycles. */
|
/* - Computation of CPU clock cycles corresponding to ADC clock cycles. */
|
||||||
/* - Wait for the expected ADC clock cycles delay */
|
/* - Wait for the expected ADC clock cycles delay */
|
||||||
wait_loop_index = ((SystemCoreClock
|
wait_loop_index = ((SystemCoreClock / HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_ADC)) * ADC_PRECALIBRATION_DELAY_ADCCLOCKCYCLES);
|
||||||
/ HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_ADC))
|
|
||||||
* ADC_PRECALIBRATION_DELAY_ADCCLOCKCYCLES );
|
|
||||||
|
|
||||||
while(wait_loop_index != 0U)
|
while (wait_loop_index != 0U) {
|
||||||
{
|
|
||||||
wait_loop_index--;
|
wait_loop_index--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,14 +180,10 @@ HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait for calibration reset completion */
|
/* Wait for calibration reset completion */
|
||||||
while(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_RSTCAL))
|
while (HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_RSTCAL)) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > ADC_CALIBRATION_TIMEOUT) {
|
||||||
if((HAL_GetTick() - tickstart) > ADC_CALIBRATION_TIMEOUT)
|
|
||||||
{
|
|
||||||
/* Update ADC state machine to error */
|
/* Update ADC state machine to error */
|
||||||
ADC_STATE_CLR_SET(hadc->State,
|
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_BUSY_INTERNAL, HAL_ADC_STATE_ERROR_INTERNAL);
|
||||||
HAL_ADC_STATE_BUSY_INTERNAL,
|
|
||||||
HAL_ADC_STATE_ERROR_INTERNAL);
|
|
||||||
|
|
||||||
/* Process unlocked */
|
/* Process unlocked */
|
||||||
__HAL_UNLOCK(hadc);
|
__HAL_UNLOCK(hadc);
|
||||||
@@ -203,21 +192,16 @@ HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* 4. Start ADC calibration */
|
/* 4. Start ADC calibration */
|
||||||
SET_BIT(hadc->Instance->CR2, ADC_CR2_CAL);
|
SET_BIT(hadc->Instance->CR2, ADC_CR2_CAL);
|
||||||
|
|
||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait for calibration completion */
|
/* Wait for calibration completion */
|
||||||
while(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_CAL))
|
while (HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_CAL)) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > ADC_CALIBRATION_TIMEOUT) {
|
||||||
if((HAL_GetTick() - tickstart) > ADC_CALIBRATION_TIMEOUT)
|
|
||||||
{
|
|
||||||
/* Update ADC state machine to error */
|
/* Update ADC state machine to error */
|
||||||
ADC_STATE_CLR_SET(hadc->State,
|
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_BUSY_INTERNAL, HAL_ADC_STATE_ERROR_INTERNAL);
|
||||||
HAL_ADC_STATE_BUSY_INTERNAL,
|
|
||||||
HAL_ADC_STATE_ERROR_INTERNAL);
|
|
||||||
|
|
||||||
/* Process unlocked */
|
/* Process unlocked */
|
||||||
__HAL_UNLOCK(hadc);
|
__HAL_UNLOCK(hadc);
|
||||||
@@ -227,9 +211,7 @@ HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set ADC state */
|
/* Set ADC state */
|
||||||
ADC_STATE_CLR_SET(hadc->State,
|
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_BUSY_INTERNAL, HAL_ADC_STATE_READY);
|
||||||
HAL_ADC_STATE_BUSY_INTERNAL,
|
|
||||||
HAL_ADC_STATE_READY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process unlocked */
|
/* Process unlocked */
|
||||||
@@ -245,8 +227,7 @@ HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
|
|||||||
* @param hadc: ADC handle
|
* @param hadc: ADC handle
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
|
HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef *hadc) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -259,23 +240,17 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
|
|||||||
tmp_hal_status = ADC_Enable(hadc);
|
tmp_hal_status = ADC_Enable(hadc);
|
||||||
|
|
||||||
/* Start conversion if ADC is effectively enabled */
|
/* Start conversion if ADC is effectively enabled */
|
||||||
if (tmp_hal_status == HAL_OK)
|
if (tmp_hal_status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Set ADC state */
|
/* Set ADC state */
|
||||||
/* - Clear state bitfield related to injected group conversion results */
|
/* - Clear state bitfield related to injected group conversion results */
|
||||||
/* - Set state bitfield related to injected operation */
|
/* - Set state bitfield related to injected operation */
|
||||||
ADC_STATE_CLR_SET(hadc->State,
|
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
|
||||||
HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
|
|
||||||
HAL_ADC_STATE_INJ_BUSY);
|
|
||||||
|
|
||||||
/* Case of independent mode or multimode (for devices with several ADCs): */
|
/* Case of independent mode or multimode (for devices with several ADCs): */
|
||||||
/* Set multimode state. */
|
/* Set multimode state. */
|
||||||
if (ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc))
|
if (ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc)) {
|
||||||
{
|
|
||||||
CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
|
CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
|
SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,8 +258,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
|
|||||||
/* Note: On this device, there is no ADC error code fields related to */
|
/* Note: On this device, there is no ADC error code fields related to */
|
||||||
/* conversions on group injected only. In case of conversion on */
|
/* conversions on group injected only. In case of conversion on */
|
||||||
/* going on group regular, no error code is reset. */
|
/* going on group regular, no error code is reset. */
|
||||||
if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
|
if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY)) {
|
||||||
{
|
|
||||||
/* Reset ADC all error code fields */
|
/* Reset ADC all error code fields */
|
||||||
ADC_CLEAR_ERRORCODE(hadc);
|
ADC_CLEAR_ERRORCODE(hadc);
|
||||||
}
|
}
|
||||||
@@ -307,23 +281,16 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
|
|||||||
/* Case of multimode enabled (for devices with several ADCs): if ADC is */
|
/* Case of multimode enabled (for devices with several ADCs): if ADC is */
|
||||||
/* slave, ADC is enabled only (conversion is not started). If ADC is */
|
/* slave, ADC is enabled only (conversion is not started). If ADC is */
|
||||||
/* master, ADC is enabled and conversion is started. */
|
/* master, ADC is enabled and conversion is started. */
|
||||||
if (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO))
|
if (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO)) {
|
||||||
{
|
if (ADC_IS_SOFTWARE_START_INJECTED(hadc) && ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc)) {
|
||||||
if (ADC_IS_SOFTWARE_START_INJECTED(hadc) &&
|
|
||||||
ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc) )
|
|
||||||
{
|
|
||||||
/* Start ADC conversion on injected group with SW start */
|
/* Start ADC conversion on injected group with SW start */
|
||||||
SET_BIT(hadc->Instance->CR2, (ADC_CR2_JSWSTART | ADC_CR2_JEXTTRIG));
|
SET_BIT(hadc->Instance->CR2, (ADC_CR2_JSWSTART | ADC_CR2_JEXTTRIG));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Start ADC conversion on injected group with external trigger */
|
/* Start ADC conversion on injected group with external trigger */
|
||||||
SET_BIT(hadc->Instance->CR2, ADC_CR2_JEXTTRIG);
|
SET_BIT(hadc->Instance->CR2, ADC_CR2_JEXTTRIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Process unlocked */
|
/* Process unlocked */
|
||||||
__HAL_UNLOCK(hadc);
|
__HAL_UNLOCK(hadc);
|
||||||
}
|
}
|
||||||
@@ -344,8 +311,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
|
|||||||
* @param hadc: ADC handle
|
* @param hadc: ADC handle
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
|
HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef *hadc) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -360,24 +326,17 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
|
|||||||
/* continue (injected and regular groups stop conversion and ADC disable */
|
/* continue (injected and regular groups stop conversion and ADC disable */
|
||||||
/* are common) */
|
/* are common) */
|
||||||
/* - In case of auto-injection mode, HAL_ADC_Stop must be used. */
|
/* - In case of auto-injection mode, HAL_ADC_Stop must be used. */
|
||||||
if(((hadc->State & HAL_ADC_STATE_REG_BUSY) == RESET) &&
|
if (((hadc->State & HAL_ADC_STATE_REG_BUSY) == RESET) && HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO)) {
|
||||||
HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) )
|
|
||||||
{
|
|
||||||
/* Stop potential conversion on going, on regular and injected groups */
|
/* Stop potential conversion on going, on regular and injected groups */
|
||||||
/* Disable ADC peripheral */
|
/* Disable ADC peripheral */
|
||||||
tmp_hal_status = ADC_ConversionStop_Disable(hadc);
|
tmp_hal_status = ADC_ConversionStop_Disable(hadc);
|
||||||
|
|
||||||
/* Check if ADC is effectively disabled */
|
/* Check if ADC is effectively disabled */
|
||||||
if (tmp_hal_status == HAL_OK)
|
if (tmp_hal_status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Set ADC state */
|
/* Set ADC state */
|
||||||
ADC_STATE_CLR_SET(hadc->State,
|
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, HAL_ADC_STATE_READY);
|
||||||
HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
|
|
||||||
HAL_ADC_STATE_READY);
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Update ADC state machine to error */
|
/* Update ADC state machine to error */
|
||||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||||
|
|
||||||
@@ -397,8 +356,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
|
|||||||
* @param Timeout: Timeout value in millisecond.
|
* @param Timeout: Timeout value in millisecond.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
|
HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout) {
|
||||||
{
|
|
||||||
uint32_t tickstart;
|
uint32_t tickstart;
|
||||||
|
|
||||||
/* Variables for polling in case of scan mode enabled and polling for each */
|
/* Variables for polling in case of scan mode enabled and polling for each */
|
||||||
@@ -428,16 +386,12 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
|
|||||||
/* settings, conversion time range can be from 28 to 32256 CPU cycles). */
|
/* settings, conversion time range can be from 28 to 32256 CPU cycles). */
|
||||||
/* As flag JEOC is not set after each conversion, no timeout status can */
|
/* As flag JEOC is not set after each conversion, no timeout status can */
|
||||||
/* be set. */
|
/* be set. */
|
||||||
if ((hadc->Instance->JSQR & ADC_JSQR_JL) == RESET)
|
if ((hadc->Instance->JSQR & ADC_JSQR_JL) == RESET) {
|
||||||
{
|
|
||||||
/* Wait until End of Conversion flag is raised */
|
/* Wait until End of Conversion flag is raised */
|
||||||
while(HAL_IS_BIT_CLR(hadc->Instance->SR, ADC_FLAG_JEOC))
|
while (HAL_IS_BIT_CLR(hadc->Instance->SR, ADC_FLAG_JEOC)) {
|
||||||
{
|
|
||||||
/* Check if timeout is disabled (set to infinite wait) */
|
/* Check if timeout is disabled (set to infinite wait) */
|
||||||
if(Timeout != HAL_MAX_DELAY)
|
if (Timeout != HAL_MAX_DELAY) {
|
||||||
{
|
if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout)) {
|
||||||
if((Timeout == 0U) || ((HAL_GetTick() - tickstart ) > Timeout))
|
|
||||||
{
|
|
||||||
/* Update ADC state machine to timeout */
|
/* Update ADC state machine to timeout */
|
||||||
SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
|
SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
|
||||||
|
|
||||||
@@ -448,24 +402,17 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Replace polling by wait for maximum conversion time */
|
/* Replace polling by wait for maximum conversion time */
|
||||||
/* - Computation of CPU clock cycles corresponding to ADC clock cycles */
|
/* - Computation of CPU clock cycles corresponding to ADC clock cycles */
|
||||||
/* and ADC maximum conversion cycles on all channels. */
|
/* and ADC maximum conversion cycles on all channels. */
|
||||||
/* - Wait for the expected ADC clock cycles delay */
|
/* - Wait for the expected ADC clock cycles delay */
|
||||||
Conversion_Timeout_CPU_cycles_max = ((SystemCoreClock
|
Conversion_Timeout_CPU_cycles_max = ((SystemCoreClock / HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_ADC)) * ADC_CONVCYCLES_MAX_RANGE(hadc));
|
||||||
/ HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_ADC))
|
|
||||||
* ADC_CONVCYCLES_MAX_RANGE(hadc) );
|
|
||||||
|
|
||||||
while(Conversion_Timeout_CPU_cycles < Conversion_Timeout_CPU_cycles_max)
|
while (Conversion_Timeout_CPU_cycles < Conversion_Timeout_CPU_cycles_max) {
|
||||||
{
|
|
||||||
/* Check if timeout is disabled (set to infinite wait) */
|
/* Check if timeout is disabled (set to infinite wait) */
|
||||||
if(Timeout != HAL_MAX_DELAY)
|
if (Timeout != HAL_MAX_DELAY) {
|
||||||
{
|
if ((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout)) {
|
||||||
if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
|
|
||||||
{
|
|
||||||
/* Update ADC state machine to timeout */
|
/* Update ADC state machine to timeout */
|
||||||
SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
|
SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
|
||||||
|
|
||||||
@@ -475,7 +422,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
|
|||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Conversion_Timeout_CPU_cycles ++;
|
Conversion_Timeout_CPU_cycles++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -490,16 +437,11 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
|
|||||||
/* Determine whether any further conversion upcoming on group injected */
|
/* Determine whether any further conversion upcoming on group injected */
|
||||||
/* by external trigger or by automatic injected conversion */
|
/* by external trigger or by automatic injected conversion */
|
||||||
/* from group regular. */
|
/* from group regular. */
|
||||||
if(ADC_IS_SOFTWARE_START_INJECTED(hadc) ||
|
if (ADC_IS_SOFTWARE_START_INJECTED(hadc) || (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) && (ADC_IS_SOFTWARE_START_REGULAR(hadc) && (hadc->Init.ContinuousConvMode == DISABLE)))) {
|
||||||
(HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) &&
|
|
||||||
(ADC_IS_SOFTWARE_START_REGULAR(hadc) &&
|
|
||||||
(hadc->Init.ContinuousConvMode == DISABLE) ) ) )
|
|
||||||
{
|
|
||||||
/* Set ADC state */
|
/* Set ADC state */
|
||||||
CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
|
CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
|
||||||
|
|
||||||
if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
|
if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY)) {
|
||||||
{
|
|
||||||
SET_BIT(hadc->State, HAL_ADC_STATE_READY);
|
SET_BIT(hadc->State, HAL_ADC_STATE_READY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -515,8 +457,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
|
|||||||
* @param hadc: ADC handle
|
* @param hadc: ADC handle
|
||||||
* @retval HAL status.
|
* @retval HAL status.
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
|
HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef *hadc) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -529,23 +470,17 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
|
|||||||
tmp_hal_status = ADC_Enable(hadc);
|
tmp_hal_status = ADC_Enable(hadc);
|
||||||
|
|
||||||
/* Start conversion if ADC is effectively enabled */
|
/* Start conversion if ADC is effectively enabled */
|
||||||
if (tmp_hal_status == HAL_OK)
|
if (tmp_hal_status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Set ADC state */
|
/* Set ADC state */
|
||||||
/* - Clear state bitfield related to injected group conversion results */
|
/* - Clear state bitfield related to injected group conversion results */
|
||||||
/* - Set state bitfield related to injected operation */
|
/* - Set state bitfield related to injected operation */
|
||||||
ADC_STATE_CLR_SET(hadc->State,
|
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
|
||||||
HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
|
|
||||||
HAL_ADC_STATE_INJ_BUSY);
|
|
||||||
|
|
||||||
/* Case of independent mode or multimode (for devices with several ADCs): */
|
/* Case of independent mode or multimode (for devices with several ADCs): */
|
||||||
/* Set multimode state. */
|
/* Set multimode state. */
|
||||||
if (ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc))
|
if (ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc)) {
|
||||||
{
|
|
||||||
CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
|
CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
|
SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,8 +488,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
|
|||||||
/* Note: On this device, there is no ADC error code fields related to */
|
/* Note: On this device, there is no ADC error code fields related to */
|
||||||
/* conversions on group injected only. In case of conversion on */
|
/* conversions on group injected only. In case of conversion on */
|
||||||
/* going on group regular, no error code is reset. */
|
/* going on group regular, no error code is reset. */
|
||||||
if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
|
if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY)) {
|
||||||
{
|
|
||||||
/* Reset ADC all error code fields */
|
/* Reset ADC all error code fields */
|
||||||
ADC_CLEAR_ERRORCODE(hadc);
|
ADC_CLEAR_ERRORCODE(hadc);
|
||||||
}
|
}
|
||||||
@@ -577,23 +511,16 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
|
|||||||
/* trigger event. */
|
/* trigger event. */
|
||||||
/* If automatic injected conversion is enabled, conversion will start */
|
/* If automatic injected conversion is enabled, conversion will start */
|
||||||
/* after next regular group conversion. */
|
/* after next regular group conversion. */
|
||||||
if (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO))
|
if (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO)) {
|
||||||
{
|
if (ADC_IS_SOFTWARE_START_INJECTED(hadc) && ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc)) {
|
||||||
if (ADC_IS_SOFTWARE_START_INJECTED(hadc) &&
|
|
||||||
ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc) )
|
|
||||||
{
|
|
||||||
/* Start ADC conversion on injected group with SW start */
|
/* Start ADC conversion on injected group with SW start */
|
||||||
SET_BIT(hadc->Instance->CR2, (ADC_CR2_JSWSTART | ADC_CR2_JEXTTRIG));
|
SET_BIT(hadc->Instance->CR2, (ADC_CR2_JSWSTART | ADC_CR2_JEXTTRIG));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Start ADC conversion on injected group with external trigger */
|
/* Start ADC conversion on injected group with external trigger */
|
||||||
SET_BIT(hadc->Instance->CR2, ADC_CR2_JEXTTRIG);
|
SET_BIT(hadc->Instance->CR2, ADC_CR2_JEXTTRIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Process unlocked */
|
/* Process unlocked */
|
||||||
__HAL_UNLOCK(hadc);
|
__HAL_UNLOCK(hadc);
|
||||||
}
|
}
|
||||||
@@ -614,8 +541,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
|
|||||||
* @param hadc: ADC handle
|
* @param hadc: ADC handle
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
|
HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef *hadc) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -630,27 +556,20 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
|
|||||||
/* continue (injected and regular groups stop conversion and ADC disable */
|
/* continue (injected and regular groups stop conversion and ADC disable */
|
||||||
/* are common) */
|
/* are common) */
|
||||||
/* - In case of auto-injection mode, HAL_ADC_Stop must be used. */
|
/* - In case of auto-injection mode, HAL_ADC_Stop must be used. */
|
||||||
if(((hadc->State & HAL_ADC_STATE_REG_BUSY) == RESET) &&
|
if (((hadc->State & HAL_ADC_STATE_REG_BUSY) == RESET) && HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO)) {
|
||||||
HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) )
|
|
||||||
{
|
|
||||||
/* Stop potential conversion on going, on regular and injected groups */
|
/* Stop potential conversion on going, on regular and injected groups */
|
||||||
/* Disable ADC peripheral */
|
/* Disable ADC peripheral */
|
||||||
tmp_hal_status = ADC_ConversionStop_Disable(hadc);
|
tmp_hal_status = ADC_ConversionStop_Disable(hadc);
|
||||||
|
|
||||||
/* Check if ADC is effectively disabled */
|
/* Check if ADC is effectively disabled */
|
||||||
if (tmp_hal_status == HAL_OK)
|
if (tmp_hal_status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Disable ADC end of conversion interrupt for injected channels */
|
/* Disable ADC end of conversion interrupt for injected channels */
|
||||||
__HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC);
|
__HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC);
|
||||||
|
|
||||||
/* Set ADC state */
|
/* Set ADC state */
|
||||||
ADC_STATE_CLR_SET(hadc->State,
|
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, HAL_ADC_STATE_READY);
|
||||||
HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
|
|
||||||
HAL_ADC_STATE_READY);
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Update ADC state machine to error */
|
/* Update ADC state machine to error */
|
||||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||||
|
|
||||||
@@ -664,7 +583,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
|
|||||||
return tmp_hal_status;
|
return tmp_hal_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
|
#if defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F105xC) || defined(STM32F107xC) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||||
/**
|
/**
|
||||||
* @brief Enables ADC, starts conversion of regular group and transfers result
|
* @brief Enables ADC, starts conversion of regular group and transfers result
|
||||||
* through DMA.
|
* through DMA.
|
||||||
@@ -683,8 +602,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
|
|||||||
* @param Length: The length of data to be transferred from ADC peripheral to memory.
|
* @param Length: The length of data to be transferred from ADC peripheral to memory.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)
|
HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||||
ADC_HandleTypeDef tmphadcSlave;
|
ADC_HandleTypeDef tmphadcSlave;
|
||||||
|
|
||||||
@@ -702,8 +620,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
|
|||||||
/* conversion trigger ADC_SOFTWARE_START. */
|
/* conversion trigger ADC_SOFTWARE_START. */
|
||||||
/* Note: External trigger of ADC slave must be enabled, it is already done */
|
/* Note: External trigger of ADC slave must be enabled, it is already done */
|
||||||
/* into function "HAL_ADC_Init()". */
|
/* into function "HAL_ADC_Init()". */
|
||||||
if(!ADC_IS_SOFTWARE_START_REGULAR(&tmphadcSlave))
|
if (!ADC_IS_SOFTWARE_START_REGULAR(&tmphadcSlave)) {
|
||||||
{
|
|
||||||
/* Update ADC state machine to error */
|
/* Update ADC state machine to error */
|
||||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||||
|
|
||||||
@@ -716,25 +633,20 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
|
|||||||
/* Enable the ADC peripherals: master and slave (in case if not already */
|
/* Enable the ADC peripherals: master and slave (in case if not already */
|
||||||
/* enabled previously) */
|
/* enabled previously) */
|
||||||
tmp_hal_status = ADC_Enable(hadc);
|
tmp_hal_status = ADC_Enable(hadc);
|
||||||
if (tmp_hal_status == HAL_OK)
|
if (tmp_hal_status == HAL_OK) {
|
||||||
{
|
|
||||||
tmp_hal_status = ADC_Enable(&tmphadcSlave);
|
tmp_hal_status = ADC_Enable(&tmphadcSlave);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start conversion if all ADCs of multimode are effectively enabled */
|
/* Start conversion if all ADCs of multimode are effectively enabled */
|
||||||
if (tmp_hal_status == HAL_OK)
|
if (tmp_hal_status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Set ADC state (ADC master) */
|
/* Set ADC state (ADC master) */
|
||||||
/* - Clear state bitfield related to regular group conversion results */
|
/* - Clear state bitfield related to regular group conversion results */
|
||||||
/* - Set state bitfield related to regular operation */
|
/* - Set state bitfield related to regular operation */
|
||||||
ADC_STATE_CLR_SET(hadc->State,
|
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_MULTIMODE_SLAVE, HAL_ADC_STATE_REG_BUSY);
|
||||||
HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_MULTIMODE_SLAVE,
|
|
||||||
HAL_ADC_STATE_REG_BUSY);
|
|
||||||
|
|
||||||
/* If conversions on group regular are also triggering group injected, */
|
/* If conversions on group regular are also triggering group injected, */
|
||||||
/* update ADC state. */
|
/* update ADC state. */
|
||||||
if (READ_BIT(hadc->Instance->CR1, ADC_CR1_JAUTO) != RESET)
|
if (READ_BIT(hadc->Instance->CR1, ADC_CR1_JAUTO) != RESET) {
|
||||||
{
|
|
||||||
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
|
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -746,7 +658,6 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
|
|||||||
/* Set ADC error code to none */
|
/* Set ADC error code to none */
|
||||||
ADC_CLEAR_ERRORCODE(hadc);
|
ADC_CLEAR_ERRORCODE(hadc);
|
||||||
|
|
||||||
|
|
||||||
/* Set the DMA transfer complete callback */
|
/* Set the DMA transfer complete callback */
|
||||||
hadc->DMA_Handle->XferCpltCallback = ADC_DMAConvCplt;
|
hadc->DMA_Handle->XferCpltCallback = ADC_DMAConvCplt;
|
||||||
|
|
||||||
@@ -756,7 +667,6 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
|
|||||||
/* Set the DMA error callback */
|
/* Set the DMA error callback */
|
||||||
hadc->DMA_Handle->XferErrorCallback = ADC_DMAError;
|
hadc->DMA_Handle->XferErrorCallback = ADC_DMAError;
|
||||||
|
|
||||||
|
|
||||||
/* Manage ADC and DMA start: ADC overrun interruption, DMA start, ADC */
|
/* Manage ADC and DMA start: ADC overrun interruption, DMA start, ADC */
|
||||||
/* start (in case of SW start): */
|
/* start (in case of SW start): */
|
||||||
|
|
||||||
@@ -775,19 +685,14 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
|
|||||||
/* trigger event. */
|
/* trigger event. */
|
||||||
/* Note: Alternate trigger for single conversion could be to force an */
|
/* Note: Alternate trigger for single conversion could be to force an */
|
||||||
/* additional set of bit ADON "hadc->Instance->CR2 |= ADC_CR2_ADON;"*/
|
/* additional set of bit ADON "hadc->Instance->CR2 |= ADC_CR2_ADON;"*/
|
||||||
if (ADC_IS_SOFTWARE_START_REGULAR(hadc))
|
if (ADC_IS_SOFTWARE_START_REGULAR(hadc)) {
|
||||||
{
|
|
||||||
/* Start ADC conversion on regular group with SW start */
|
/* Start ADC conversion on regular group with SW start */
|
||||||
SET_BIT(hadc->Instance->CR2, (ADC_CR2_SWSTART | ADC_CR2_EXTTRIG));
|
SET_BIT(hadc->Instance->CR2, (ADC_CR2_SWSTART | ADC_CR2_EXTTRIG));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Start ADC conversion on regular group with external trigger */
|
/* Start ADC conversion on regular group with external trigger */
|
||||||
SET_BIT(hadc->Instance->CR2, ADC_CR2_EXTTRIG);
|
SET_BIT(hadc->Instance->CR2, ADC_CR2_EXTTRIG);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Process unlocked */
|
/* Process unlocked */
|
||||||
__HAL_UNLOCK(hadc);
|
__HAL_UNLOCK(hadc);
|
||||||
}
|
}
|
||||||
@@ -809,8 +714,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
|
|||||||
* @param hadc: ADC handle of ADC master (handle of ADC slave must not be used)
|
* @param hadc: ADC handle of ADC master (handle of ADC slave must not be used)
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
|
HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef *hadc) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||||
ADC_HandleTypeDef tmphadcSlave;
|
ADC_HandleTypeDef tmphadcSlave;
|
||||||
|
|
||||||
@@ -820,14 +724,12 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
|
|||||||
/* Process locked */
|
/* Process locked */
|
||||||
__HAL_LOCK(hadc);
|
__HAL_LOCK(hadc);
|
||||||
|
|
||||||
|
|
||||||
/* Stop potential conversion on going, on regular and injected groups */
|
/* Stop potential conversion on going, on regular and injected groups */
|
||||||
/* Disable ADC master peripheral */
|
/* Disable ADC master peripheral */
|
||||||
tmp_hal_status = ADC_ConversionStop_Disable(hadc);
|
tmp_hal_status = ADC_ConversionStop_Disable(hadc);
|
||||||
|
|
||||||
/* Check if ADC is effectively disabled */
|
/* Check if ADC is effectively disabled */
|
||||||
if(tmp_hal_status == HAL_OK)
|
if (tmp_hal_status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Set a temporary handle of the ADC slave associated to the ADC master */
|
/* Set a temporary handle of the ADC slave associated to the ADC master */
|
||||||
ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
|
ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
|
||||||
|
|
||||||
@@ -835,8 +737,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
|
|||||||
tmp_hal_status = ADC_ConversionStop_Disable(&tmphadcSlave);
|
tmp_hal_status = ADC_ConversionStop_Disable(&tmphadcSlave);
|
||||||
|
|
||||||
/* Check if ADC is effectively disabled */
|
/* Check if ADC is effectively disabled */
|
||||||
if(tmp_hal_status != HAL_OK)
|
if (tmp_hal_status != HAL_OK) {
|
||||||
{
|
|
||||||
/* Update ADC state machine to error */
|
/* Update ADC state machine to error */
|
||||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
|
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
|
||||||
|
|
||||||
@@ -857,9 +758,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
|
|||||||
tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
|
tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
|
||||||
|
|
||||||
/* Change ADC state (ADC master) */
|
/* Change ADC state (ADC master) */
|
||||||
ADC_STATE_CLR_SET(hadc->State,
|
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, HAL_ADC_STATE_READY);
|
||||||
HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
|
|
||||||
HAL_ADC_STATE_READY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process unlocked */
|
/* Process unlocked */
|
||||||
@@ -898,8 +797,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
|
|||||||
* @arg ADC_INJECTED_RANK_4: Injected Channel4 selected
|
* @arg ADC_INJECTED_RANK_4: Injected Channel4 selected
|
||||||
* @retval ADC group injected conversion data
|
* @retval ADC group injected conversion data
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank)
|
uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef *hadc, uint32_t InjectedRank) {
|
||||||
{
|
|
||||||
uint32_t tmp_jdr = 0U;
|
uint32_t tmp_jdr = 0U;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -907,8 +805,7 @@ uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRa
|
|||||||
assert_param(IS_ADC_INJECTED_RANK(InjectedRank));
|
assert_param(IS_ADC_INJECTED_RANK(InjectedRank));
|
||||||
|
|
||||||
/* Get ADC converted value */
|
/* Get ADC converted value */
|
||||||
switch(InjectedRank)
|
switch (InjectedRank) {
|
||||||
{
|
|
||||||
case ADC_INJECTED_RANK_4:
|
case ADC_INJECTED_RANK_4:
|
||||||
tmp_jdr = hadc->Instance->JDR4;
|
tmp_jdr = hadc->Instance->JDR4;
|
||||||
break;
|
break;
|
||||||
@@ -928,15 +825,14 @@ uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRa
|
|||||||
return tmp_jdr;
|
return tmp_jdr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
|
#if defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F105xC) || defined(STM32F107xC) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||||
/**
|
/**
|
||||||
* @brief Returns the last ADC Master&Slave regular conversions results data
|
* @brief Returns the last ADC Master&Slave regular conversions results data
|
||||||
* in the selected multi mode.
|
* in the selected multi mode.
|
||||||
* @param hadc: ADC handle of ADC master (handle of ADC slave must not be used)
|
* @param hadc: ADC handle of ADC master (handle of ADC slave must not be used)
|
||||||
* @retval The converted data value.
|
* @retval The converted data value.
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc)
|
uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef *hadc) {
|
||||||
{
|
|
||||||
uint32_t tmpDR = 0U;
|
uint32_t tmpDR = 0U;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -952,8 +848,7 @@ uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc)
|
|||||||
/* only if ADC1 DMA mode is enabled. */
|
/* only if ADC1 DMA mode is enabled. */
|
||||||
tmpDR = hadc->Instance->DR;
|
tmpDR = hadc->Instance->DR;
|
||||||
|
|
||||||
if (HAL_IS_BIT_CLR(ADC1->CR2, ADC_CR2_DMA))
|
if (HAL_IS_BIT_CLR(ADC1->CR2, ADC_CR2_DMA)) {
|
||||||
{
|
|
||||||
tmpDR |= (ADC2->DR << 16U);
|
tmpDR |= (ADC2->DR << 16U);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -967,8 +862,7 @@ uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc)
|
|||||||
* @param hadc: ADC handle
|
* @param hadc: ADC handle
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc)
|
__weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc) {
|
||||||
{
|
|
||||||
/* Prevent unused argument(s) compilation warning */
|
/* Prevent unused argument(s) compilation warning */
|
||||||
UNUSED(hadc);
|
UNUSED(hadc);
|
||||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||||
@@ -1009,8 +903,7 @@ __weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc)
|
|||||||
* injected group.
|
* injected group.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_InjectionConfTypeDef* sConfigInjected)
|
HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef *hadc, ADC_InjectionConfTypeDef *sConfigInjected) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||||
__IO uint32_t wait_loop_index = 0U;
|
__IO uint32_t wait_loop_index = 0U;
|
||||||
|
|
||||||
@@ -1022,8 +915,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
|
|||||||
assert_param(IS_ADC_EXTTRIGINJEC(sConfigInjected->ExternalTrigInjecConv));
|
assert_param(IS_ADC_EXTTRIGINJEC(sConfigInjected->ExternalTrigInjecConv));
|
||||||
assert_param(IS_ADC_RANGE(sConfigInjected->InjectedOffset));
|
assert_param(IS_ADC_RANGE(sConfigInjected->InjectedOffset));
|
||||||
|
|
||||||
if(hadc->Init.ScanConvMode != ADC_SCAN_DISABLE)
|
if (hadc->Init.ScanConvMode != ADC_SCAN_DISABLE) {
|
||||||
{
|
|
||||||
assert_param(IS_ADC_INJECTED_RANK(sConfigInjected->InjectedRank));
|
assert_param(IS_ADC_INJECTED_RANK(sConfigInjected->InjectedRank));
|
||||||
assert_param(IS_ADC_INJECTED_NB_CONV(sConfigInjected->InjectedNbrOfConversion));
|
assert_param(IS_ADC_INJECTED_NB_CONV(sConfigInjected->InjectedNbrOfConversion));
|
||||||
assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedDiscontinuousConvMode));
|
assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedDiscontinuousConvMode));
|
||||||
@@ -1041,61 +933,50 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
|
|||||||
/* conversions is forced to 0x00 for alignment over all STM32 devices. */
|
/* conversions is forced to 0x00 for alignment over all STM32 devices. */
|
||||||
/* - if scan mode is enabled, injected channels sequence length is set to */
|
/* - if scan mode is enabled, injected channels sequence length is set to */
|
||||||
/* parameter "InjectedNbrOfConversion". */
|
/* parameter "InjectedNbrOfConversion". */
|
||||||
// if (hadc->Init.ScanConvMode == ADC_SCAN_DISABLE)
|
// if (hadc->Init.ScanConvMode == ADC_SCAN_DISABLE)
|
||||||
// {
|
// {
|
||||||
// if (sConfigInjected->InjectedRank == ADC_INJECTED_RANK_1)
|
// if (sConfigInjected->InjectedRank == ADC_INJECTED_RANK_1)
|
||||||
// {
|
// {
|
||||||
// /* Clear the old SQx bits for all injected ranks */
|
// /* Clear the old SQx bits for all injected ranks */
|
||||||
// MODIFY_REG(hadc->Instance->JSQR ,
|
// MODIFY_REG(hadc->Instance->JSQR ,
|
||||||
// ADC_JSQR_JL |
|
// ADC_JSQR_JL |
|
||||||
// ADC_JSQR_JSQ4 |
|
// ADC_JSQR_JSQ4 |
|
||||||
// ADC_JSQR_JSQ3 |
|
// ADC_JSQR_JSQ3 |
|
||||||
// ADC_JSQR_JSQ2 |
|
// ADC_JSQR_JSQ2 |
|
||||||
// ADC_JSQR_JSQ1 ,
|
// ADC_JSQR_JSQ1 ,
|
||||||
// ADC_JSQR_RK_JL(sConfigInjected->InjectedChannel,
|
// ADC_JSQR_RK_JL(sConfigInjected->InjectedChannel,
|
||||||
// ADC_INJECTED_RANK_1,
|
// ADC_INJECTED_RANK_1,
|
||||||
// 0x01U));
|
// 0x01U));
|
||||||
// }
|
// }
|
||||||
// /* If another injected rank than rank1 was intended to be set, and could */
|
// /* If another injected rank than rank1 was intended to be set, and could */
|
||||||
// /* not due to ScanConvMode disabled, error is reported. */
|
// /* not due to ScanConvMode disabled, error is reported. */
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
// /* Update ADC state machine to error */
|
// /* Update ADC state machine to error */
|
||||||
// SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
// SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||||
//
|
//
|
||||||
// tmp_hal_status = HAL_ERROR;
|
// tmp_hal_status = HAL_ERROR;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
{
|
{
|
||||||
/* Since injected channels rank conv. order depends on total number of */
|
/* Since injected channels rank conv. order depends on total number of */
|
||||||
/* injected conversions, selected rank must be below or equal to total */
|
/* injected conversions, selected rank must be below or equal to total */
|
||||||
/* number of injected conversions to be updated. */
|
/* number of injected conversions to be updated. */
|
||||||
if (sConfigInjected->InjectedRank <= sConfigInjected->InjectedNbrOfConversion)
|
if (sConfigInjected->InjectedRank <= sConfigInjected->InjectedNbrOfConversion) {
|
||||||
{
|
|
||||||
/* Clear the old SQx bits for the selected rank */
|
/* Clear the old SQx bits for the selected rank */
|
||||||
/* Set the SQx bits for the selected rank */
|
/* Set the SQx bits for the selected rank */
|
||||||
MODIFY_REG(hadc->Instance->JSQR ,
|
MODIFY_REG(hadc->Instance->JSQR,
|
||||||
|
|
||||||
ADC_JSQR_JL |
|
ADC_JSQR_JL | ADC_JSQR_RK_JL(ADC_JSQR_JSQ1, sConfigInjected->InjectedRank, sConfigInjected->InjectedNbrOfConversion),
|
||||||
ADC_JSQR_RK_JL(ADC_JSQR_JSQ1,
|
|
||||||
sConfigInjected->InjectedRank,
|
|
||||||
sConfigInjected->InjectedNbrOfConversion) ,
|
|
||||||
|
|
||||||
ADC_JSQR_JL_SHIFT(sConfigInjected->InjectedNbrOfConversion) |
|
ADC_JSQR_JL_SHIFT(sConfigInjected->InjectedNbrOfConversion)
|
||||||
ADC_JSQR_RK_JL(sConfigInjected->InjectedChannel,
|
| ADC_JSQR_RK_JL(sConfigInjected->InjectedChannel, sConfigInjected->InjectedRank, sConfigInjected->InjectedNbrOfConversion));
|
||||||
sConfigInjected->InjectedRank,
|
} else {
|
||||||
sConfigInjected->InjectedNbrOfConversion) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Clear the old SQx bits for the selected rank */
|
/* Clear the old SQx bits for the selected rank */
|
||||||
MODIFY_REG(hadc->Instance->JSQR ,
|
MODIFY_REG(hadc->Instance->JSQR,
|
||||||
|
|
||||||
ADC_JSQR_JL |
|
ADC_JSQR_JL | ADC_JSQR_RK_JL(ADC_JSQR_JSQ1, sConfigInjected->InjectedRank, sConfigInjected->InjectedNbrOfConversion),
|
||||||
ADC_JSQR_RK_JL(ADC_JSQR_JSQ1,
|
|
||||||
sConfigInjected->InjectedRank,
|
|
||||||
sConfigInjected->InjectedNbrOfConversion) ,
|
|
||||||
|
|
||||||
0x00000000U);
|
0x00000000U);
|
||||||
}
|
}
|
||||||
@@ -1110,29 +991,20 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
|
|||||||
/* - Injected discontinuous mode */
|
/* - Injected discontinuous mode */
|
||||||
/* Note: In case of ADC already enabled, caution to not launch an unwanted */
|
/* Note: In case of ADC already enabled, caution to not launch an unwanted */
|
||||||
/* conversion while modifying register CR2 by writing 1 to bit ADON. */
|
/* conversion while modifying register CR2 by writing 1 to bit ADON. */
|
||||||
if (ADC_IS_ENABLE(hadc) == RESET)
|
if (ADC_IS_ENABLE(hadc) == RESET) {
|
||||||
{
|
MODIFY_REG(hadc->Instance->CR2, ADC_CR2_JEXTSEL | ADC_CR2_ADON, ADC_CFGR_JEXTSEL(hadc, sConfigInjected->ExternalTrigInjecConv));
|
||||||
MODIFY_REG(hadc->Instance->CR2 ,
|
|
||||||
ADC_CR2_JEXTSEL |
|
|
||||||
ADC_CR2_ADON ,
|
|
||||||
ADC_CFGR_JEXTSEL(hadc, sConfigInjected->ExternalTrigInjecConv) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Configuration of injected group */
|
/* Configuration of injected group */
|
||||||
/* - Automatic injected conversion */
|
/* - Automatic injected conversion */
|
||||||
/* - Injected discontinuous mode */
|
/* - Injected discontinuous mode */
|
||||||
|
|
||||||
/* Automatic injected conversion can be enabled if injected group */
|
/* Automatic injected conversion can be enabled if injected group */
|
||||||
/* external triggers are disabled. */
|
/* external triggers are disabled. */
|
||||||
if (sConfigInjected->AutoInjectedConv == ENABLE)
|
if (sConfigInjected->AutoInjectedConv == ENABLE) {
|
||||||
{
|
if (sConfigInjected->ExternalTrigInjecConv == ADC_INJECTED_SOFTWARE_START) {
|
||||||
if (sConfigInjected->ExternalTrigInjecConv == ADC_INJECTED_SOFTWARE_START)
|
|
||||||
{
|
|
||||||
SET_BIT(hadc->Instance->CR1, ADC_CR1_JAUTO);
|
SET_BIT(hadc->Instance->CR1, ADC_CR1_JAUTO);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Update ADC state machine to error */
|
/* Update ADC state machine to error */
|
||||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||||
|
|
||||||
@@ -1142,14 +1014,10 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
|
|||||||
|
|
||||||
/* Injected discontinuous can be enabled only if auto-injected mode is */
|
/* Injected discontinuous can be enabled only if auto-injected mode is */
|
||||||
/* disabled. */
|
/* disabled. */
|
||||||
if (sConfigInjected->InjectedDiscontinuousConvMode == ENABLE)
|
if (sConfigInjected->InjectedDiscontinuousConvMode == ENABLE) {
|
||||||
{
|
if (sConfigInjected->AutoInjectedConv == DISABLE) {
|
||||||
if (sConfigInjected->AutoInjectedConv == DISABLE)
|
|
||||||
{
|
|
||||||
SET_BIT(hadc->Instance->CR1, ADC_CR1_JDISCEN);
|
SET_BIT(hadc->Instance->CR1, ADC_CR1_JDISCEN);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Update ADC state machine to error */
|
/* Update ADC state machine to error */
|
||||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||||
|
|
||||||
@@ -1157,88 +1025,61 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* InjectedChannel sampling time configuration */
|
/* InjectedChannel sampling time configuration */
|
||||||
/* For channels 10 to 17 */
|
/* For channels 10 to 17 */
|
||||||
if (sConfigInjected->InjectedChannel >= ADC_CHANNEL_10)
|
if (sConfigInjected->InjectedChannel >= ADC_CHANNEL_10) {
|
||||||
|
MODIFY_REG(hadc->Instance->SMPR1, ADC_SMPR1(ADC_SMPR1_SMP10, sConfigInjected->InjectedChannel), ADC_SMPR1(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel));
|
||||||
|
} else /* For channels 0 to 9 */
|
||||||
{
|
{
|
||||||
MODIFY_REG(hadc->Instance->SMPR1 ,
|
MODIFY_REG(hadc->Instance->SMPR2, ADC_SMPR2(ADC_SMPR2_SMP0, sConfigInjected->InjectedChannel), ADC_SMPR2(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel));
|
||||||
ADC_SMPR1(ADC_SMPR1_SMP10, sConfigInjected->InjectedChannel) ,
|
|
||||||
ADC_SMPR1(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel) );
|
|
||||||
}
|
|
||||||
else /* For channels 0 to 9 */
|
|
||||||
{
|
|
||||||
MODIFY_REG(hadc->Instance->SMPR2 ,
|
|
||||||
ADC_SMPR2(ADC_SMPR2_SMP0, sConfigInjected->InjectedChannel) ,
|
|
||||||
ADC_SMPR2(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If ADC1 InjectedChannel_16 or InjectedChannel_17 is selected, enable Temperature sensor */
|
/* If ADC1 InjectedChannel_16 or InjectedChannel_17 is selected, enable Temperature sensor */
|
||||||
/* and VREFINT measurement path. */
|
/* and VREFINT measurement path. */
|
||||||
if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) ||
|
if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) || (sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT)) {
|
||||||
(sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT) )
|
|
||||||
{
|
|
||||||
SET_BIT(hadc->Instance->CR2, ADC_CR2_TSVREFE);
|
SET_BIT(hadc->Instance->CR2, ADC_CR2_TSVREFE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Configure the offset: offset enable/disable, InjectedChannel, offset value */
|
/* Configure the offset: offset enable/disable, InjectedChannel, offset value */
|
||||||
switch(sConfigInjected->InjectedRank)
|
switch (sConfigInjected->InjectedRank) {
|
||||||
{
|
|
||||||
case 1:
|
case 1:
|
||||||
/* Set injected channel 1 offset */
|
/* Set injected channel 1 offset */
|
||||||
MODIFY_REG(hadc->Instance->JOFR1,
|
MODIFY_REG(hadc->Instance->JOFR1, ADC_JOFR1_JOFFSET1, sConfigInjected->InjectedOffset);
|
||||||
ADC_JOFR1_JOFFSET1,
|
|
||||||
sConfigInjected->InjectedOffset);
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
/* Set injected channel 2 offset */
|
/* Set injected channel 2 offset */
|
||||||
MODIFY_REG(hadc->Instance->JOFR2,
|
MODIFY_REG(hadc->Instance->JOFR2, ADC_JOFR2_JOFFSET2, sConfigInjected->InjectedOffset);
|
||||||
ADC_JOFR2_JOFFSET2,
|
|
||||||
sConfigInjected->InjectedOffset);
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
/* Set injected channel 3 offset */
|
/* Set injected channel 3 offset */
|
||||||
MODIFY_REG(hadc->Instance->JOFR3,
|
MODIFY_REG(hadc->Instance->JOFR3, ADC_JOFR3_JOFFSET3, sConfigInjected->InjectedOffset);
|
||||||
ADC_JOFR3_JOFFSET3,
|
|
||||||
sConfigInjected->InjectedOffset);
|
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
default:
|
default:
|
||||||
MODIFY_REG(hadc->Instance->JOFR4,
|
MODIFY_REG(hadc->Instance->JOFR4, ADC_JOFR4_JOFFSET4, sConfigInjected->InjectedOffset);
|
||||||
ADC_JOFR4_JOFFSET4,
|
|
||||||
sConfigInjected->InjectedOffset);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If ADC1 Channel_16 or Channel_17 is selected, enable Temperature sensor */
|
/* If ADC1 Channel_16 or Channel_17 is selected, enable Temperature sensor */
|
||||||
/* and VREFINT measurement path. */
|
/* and VREFINT measurement path. */
|
||||||
if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) ||
|
if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) || (sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT)) {
|
||||||
(sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT) )
|
|
||||||
{
|
|
||||||
/* For STM32F1 devices with several ADC: Only ADC1 can access internal */
|
/* For STM32F1 devices with several ADC: Only ADC1 can access internal */
|
||||||
/* measurement channels (VrefInt/TempSensor). If these channels are */
|
/* measurement channels (VrefInt/TempSensor). If these channels are */
|
||||||
/* intended to be set on other ADC instances, an error is reported. */
|
/* intended to be set on other ADC instances, an error is reported. */
|
||||||
if (hadc->Instance == ADC1)
|
if (hadc->Instance == ADC1) {
|
||||||
{
|
if (READ_BIT(hadc->Instance->CR2, ADC_CR2_TSVREFE) == RESET) {
|
||||||
if (READ_BIT(hadc->Instance->CR2, ADC_CR2_TSVREFE) == RESET)
|
|
||||||
{
|
|
||||||
SET_BIT(hadc->Instance->CR2, ADC_CR2_TSVREFE);
|
SET_BIT(hadc->Instance->CR2, ADC_CR2_TSVREFE);
|
||||||
|
|
||||||
if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR))
|
if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR)) {
|
||||||
{
|
|
||||||
/* Delay for temperature sensor stabilization time */
|
/* Delay for temperature sensor stabilization time */
|
||||||
/* Compute number of CPU cycles to wait for */
|
/* Compute number of CPU cycles to wait for */
|
||||||
wait_loop_index = (ADC_TEMPSENSOR_DELAY_US * (SystemCoreClock / 1000000U));
|
wait_loop_index = (ADC_TEMPSENSOR_DELAY_US * (SystemCoreClock / 1000000U));
|
||||||
while(wait_loop_index != 0U)
|
while (wait_loop_index != 0U) {
|
||||||
{
|
|
||||||
wait_loop_index--;
|
wait_loop_index--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Update ADC state machine to error */
|
/* Update ADC state machine to error */
|
||||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||||
|
|
||||||
@@ -1253,7 +1094,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
|
|||||||
return tmp_hal_status;
|
return tmp_hal_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
|
#if defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F105xC) || defined(STM32F107xC) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||||
/**
|
/**
|
||||||
* @brief Enable ADC multimode and configure multimode parameters
|
* @brief Enable ADC multimode and configure multimode parameters
|
||||||
* @note Possibility to update parameters on the fly:
|
* @note Possibility to update parameters on the fly:
|
||||||
@@ -1270,8 +1111,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
|
|||||||
* @param multimode: Structure of ADC multimode configuration
|
* @param multimode: Structure of ADC multimode configuration
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_MultiModeTypeDef* multimode)
|
HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef *hadc, ADC_MultiModeTypeDef *multimode) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||||
ADC_HandleTypeDef tmphadcSlave;
|
ADC_HandleTypeDef tmphadcSlave;
|
||||||
|
|
||||||
@@ -1293,25 +1133,18 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_
|
|||||||
/* - Multimode mode selection */
|
/* - Multimode mode selection */
|
||||||
/* To optimize code, all multimode settings can be set when both ADCs of */
|
/* To optimize code, all multimode settings can be set when both ADCs of */
|
||||||
/* the common group are in state: disabled. */
|
/* the common group are in state: disabled. */
|
||||||
if ((ADC_IS_ENABLE(hadc) == RESET) &&
|
if ((ADC_IS_ENABLE(hadc) == RESET) && (ADC_IS_ENABLE(&tmphadcSlave) == RESET) && (IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance))) {
|
||||||
(ADC_IS_ENABLE(&tmphadcSlave) == RESET) &&
|
MODIFY_REG(hadc->Instance->CR1, ADC_CR1_DUALMOD, multimode->Mode);
|
||||||
(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance)) )
|
|
||||||
{
|
|
||||||
MODIFY_REG(hadc->Instance->CR1,
|
|
||||||
ADC_CR1_DUALMOD ,
|
|
||||||
multimode->Mode );
|
|
||||||
}
|
}
|
||||||
/* If one of the ADC sharing the same common group is enabled, no update */
|
/* If one of the ADC sharing the same common group is enabled, no update */
|
||||||
/* could be done on neither of the multimode structure parameters. */
|
/* could be done on neither of the multimode structure parameters. */
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Update ADC state machine to error */
|
/* Update ADC state machine to error */
|
||||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||||
|
|
||||||
tmp_hal_status = HAL_ERROR;
|
tmp_hal_status = HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Process unlocked */
|
/* Process unlocked */
|
||||||
__HAL_UNLOCK(hadc);
|
__HAL_UNLOCK(hadc);
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,6 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
|
/** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
|
||||||
* @brief Initialization and Configuration functions
|
* @brief Initialization and Configuration functions
|
||||||
*
|
*
|
||||||
@@ -136,7 +135,6 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the priority grouping field (preemption priority and subpriority)
|
* @brief Sets the priority grouping field (preemption priority and subpriority)
|
||||||
* using the required unlock sequence.
|
* using the required unlock sequence.
|
||||||
@@ -156,8 +154,7 @@
|
|||||||
* The pending IRQ priority will be managed only by the subpriority.
|
* The pending IRQ priority will be managed only by the subpriority.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
|
assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
|
||||||
|
|
||||||
@@ -178,8 +175,7 @@ void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
|||||||
* A lower priority value indicates a higher priority.
|
* A lower priority value indicates a higher priority.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
|
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority) {
|
||||||
{
|
|
||||||
uint32_t prioritygroup = 0x00U;
|
uint32_t prioritygroup = 0x00U;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -200,8 +196,7 @@ void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t Sub
|
|||||||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
|
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
|
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||||
|
|
||||||
@@ -216,8 +211,7 @@ void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
|
|||||||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
|
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
|
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||||
|
|
||||||
@@ -229,8 +223,7 @@ void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
|
|||||||
* @brief Initiates a system reset request to reset the MCU.
|
* @brief Initiates a system reset request to reset the MCU.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_NVIC_SystemReset(void)
|
void HAL_NVIC_SystemReset(void) {
|
||||||
{
|
|
||||||
/* System Reset */
|
/* System Reset */
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
@@ -242,10 +235,7 @@ void HAL_NVIC_SystemReset(void)
|
|||||||
* @retval status: - 0 Function succeeded.
|
* @retval status: - 0 Function succeeded.
|
||||||
* - 1 Function failed.
|
* - 1 Function failed.
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
|
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb) { return SysTick_Config(TicksNumb); }
|
||||||
{
|
|
||||||
return SysTick_Config(TicksNumb);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -271,8 +261,7 @@ uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
|
|||||||
* @brief Disables the MPU
|
* @brief Disables the MPU
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_MPU_Disable(void)
|
void HAL_MPU_Disable(void) {
|
||||||
{
|
|
||||||
/* Make sure outstanding transfers are done */
|
/* Make sure outstanding transfers are done */
|
||||||
__DMB();
|
__DMB();
|
||||||
|
|
||||||
@@ -294,8 +283,7 @@ void HAL_MPU_Disable(void)
|
|||||||
* @arg MPU_HFNMI_PRIVDEF
|
* @arg MPU_HFNMI_PRIVDEF
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_MPU_Enable(uint32_t MPU_Control)
|
void HAL_MPU_Enable(uint32_t MPU_Control) {
|
||||||
{
|
|
||||||
/* Enable the MPU */
|
/* Enable the MPU */
|
||||||
MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
|
MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
|
||||||
|
|
||||||
@@ -313,8 +301,7 @@ void HAL_MPU_Enable(uint32_t MPU_Control)
|
|||||||
* the initialization and configuration information.
|
* the initialization and configuration information.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
|
void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number));
|
assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number));
|
||||||
assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable));
|
assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable));
|
||||||
@@ -322,8 +309,7 @@ void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
|
|||||||
/* Set the Region number */
|
/* Set the Region number */
|
||||||
MPU->RNR = MPU_Init->Number;
|
MPU->RNR = MPU_Init->Number;
|
||||||
|
|
||||||
if ((MPU_Init->Enable) != RESET)
|
if ((MPU_Init->Enable) != RESET) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec));
|
assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec));
|
||||||
assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission));
|
assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission));
|
||||||
@@ -335,18 +321,10 @@ void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
|
|||||||
assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size));
|
assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size));
|
||||||
|
|
||||||
MPU->RBAR = MPU_Init->BaseAddress;
|
MPU->RBAR = MPU_Init->BaseAddress;
|
||||||
MPU->RASR = ((uint32_t)MPU_Init->DisableExec << MPU_RASR_XN_Pos) |
|
MPU->RASR = ((uint32_t)MPU_Init->DisableExec << MPU_RASR_XN_Pos) | ((uint32_t)MPU_Init->AccessPermission << MPU_RASR_AP_Pos) | ((uint32_t)MPU_Init->TypeExtField << MPU_RASR_TEX_Pos)
|
||||||
((uint32_t)MPU_Init->AccessPermission << MPU_RASR_AP_Pos) |
|
| ((uint32_t)MPU_Init->IsShareable << MPU_RASR_S_Pos) | ((uint32_t)MPU_Init->IsCacheable << MPU_RASR_C_Pos) | ((uint32_t)MPU_Init->IsBufferable << MPU_RASR_B_Pos)
|
||||||
((uint32_t)MPU_Init->TypeExtField << MPU_RASR_TEX_Pos) |
|
| ((uint32_t)MPU_Init->SubRegionDisable << MPU_RASR_SRD_Pos) | ((uint32_t)MPU_Init->Size << MPU_RASR_SIZE_Pos) | ((uint32_t)MPU_Init->Enable << MPU_RASR_ENABLE_Pos);
|
||||||
((uint32_t)MPU_Init->IsShareable << MPU_RASR_S_Pos) |
|
} else {
|
||||||
((uint32_t)MPU_Init->IsCacheable << MPU_RASR_C_Pos) |
|
|
||||||
((uint32_t)MPU_Init->IsBufferable << MPU_RASR_B_Pos) |
|
|
||||||
((uint32_t)MPU_Init->SubRegionDisable << MPU_RASR_SRD_Pos) |
|
|
||||||
((uint32_t)MPU_Init->Size << MPU_RASR_SIZE_Pos) |
|
|
||||||
((uint32_t)MPU_Init->Enable << MPU_RASR_ENABLE_Pos);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MPU->RBAR = 0x00U;
|
MPU->RBAR = 0x00U;
|
||||||
MPU->RASR = 0x00U;
|
MPU->RASR = 0x00U;
|
||||||
}
|
}
|
||||||
@@ -357,8 +335,7 @@ void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
|
|||||||
* @brief Gets the priority grouping field from the NVIC Interrupt Controller.
|
* @brief Gets the priority grouping field from the NVIC Interrupt Controller.
|
||||||
* @retval Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field)
|
* @retval Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field)
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_NVIC_GetPriorityGrouping(void)
|
uint32_t HAL_NVIC_GetPriorityGrouping(void) {
|
||||||
{
|
|
||||||
/* Get the PRIGROUP[10:8] field value */
|
/* Get the PRIGROUP[10:8] field value */
|
||||||
return NVIC_GetPriorityGrouping();
|
return NVIC_GetPriorityGrouping();
|
||||||
}
|
}
|
||||||
@@ -384,8 +361,7 @@ uint32_t HAL_NVIC_GetPriorityGrouping(void)
|
|||||||
* @param pSubPriority: Pointer on the Subpriority value (starting from 0).
|
* @param pSubPriority: Pointer on the Subpriority value (starting from 0).
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPreemptPriority, uint32_t *pSubPriority)
|
void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPreemptPriority, uint32_t *pSubPriority) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
|
assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
|
||||||
/* Get priority for Cortex-M system or device specific interrupts */
|
/* Get priority for Cortex-M system or device specific interrupts */
|
||||||
@@ -399,8 +375,7 @@ void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPre
|
|||||||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
|
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||||
|
|
||||||
@@ -417,8 +392,7 @@ void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
|||||||
* @retval status: - 0 Interrupt status is not pending.
|
* @retval status: - 0 Interrupt status is not pending.
|
||||||
* - 1 Interrupt status is pending.
|
* - 1 Interrupt status is pending.
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||||
|
|
||||||
@@ -433,8 +407,7 @@ uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
|||||||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
|
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||||
|
|
||||||
@@ -450,8 +423,7 @@ void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
|||||||
* @retval status: - 0 Interrupt status is not pending.
|
* @retval status: - 0 Interrupt status is not pending.
|
||||||
* - 1 Interrupt status is pending.
|
* - 1 Interrupt status is pending.
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
|
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||||
|
|
||||||
@@ -467,16 +439,12 @@ uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
|
|||||||
* @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
|
* @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
|
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
|
assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
|
||||||
if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
|
if (CLKSource == SYSTICK_CLKSOURCE_HCLK) {
|
||||||
{
|
|
||||||
SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
|
SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
|
SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -485,17 +453,13 @@ void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
|
|||||||
* @brief This function handles SYSTICK interrupt request.
|
* @brief This function handles SYSTICK interrupt request.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_SYSTICK_IRQHandler(void)
|
void HAL_SYSTICK_IRQHandler(void) { HAL_SYSTICK_Callback(); }
|
||||||
{
|
|
||||||
HAL_SYSTICK_Callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SYSTICK callback.
|
* @brief SYSTICK callback.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_SYSTICK_Callback(void)
|
__weak void HAL_SYSTICK_Callback(void) {
|
||||||
{
|
|
||||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||||
the HAL_SYSTICK_Callback could be implemented in the user file
|
the HAL_SYSTICK_Callback could be implemented in the user file
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -156,13 +156,11 @@ static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t
|
|||||||
* the configuration information for the specified DMA Channel.
|
* the configuration information for the specified DMA Channel.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
|
HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma) {
|
||||||
{
|
|
||||||
uint32_t tmp = 0U;
|
uint32_t tmp = 0U;
|
||||||
|
|
||||||
/* Check the DMA handle allocation */
|
/* Check the DMA handle allocation */
|
||||||
if(hdma == NULL)
|
if (hdma == NULL) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,16 +174,13 @@ HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
|
|||||||
assert_param(IS_DMA_MODE(hdma->Init.Mode));
|
assert_param(IS_DMA_MODE(hdma->Init.Mode));
|
||||||
assert_param(IS_DMA_PRIORITY(hdma->Init.Priority));
|
assert_param(IS_DMA_PRIORITY(hdma->Init.Priority));
|
||||||
|
|
||||||
#if defined (STM32F101xE) || defined (STM32F101xG) || defined (STM32F103xE) || defined (STM32F103xG) || defined (STM32F100xE) || defined (STM32F105xC) || defined (STM32F107xC)
|
#if defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F100xE) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
/* calculation of the channel index */
|
/* calculation of the channel index */
|
||||||
if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1))
|
if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1)) {
|
||||||
{
|
|
||||||
/* DMA1 */
|
/* DMA1 */
|
||||||
hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2;
|
hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2;
|
||||||
hdma->DmaBaseAddress = DMA1;
|
hdma->DmaBaseAddress = DMA1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* DMA2 */
|
/* DMA2 */
|
||||||
hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA2_Channel1) / ((uint32_t)DMA2_Channel2 - (uint32_t)DMA2_Channel1)) << 2;
|
hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA2_Channel1) / ((uint32_t)DMA2_Channel2 - (uint32_t)DMA2_Channel1)) << 2;
|
||||||
hdma->DmaBaseAddress = DMA2;
|
hdma->DmaBaseAddress = DMA2;
|
||||||
@@ -203,15 +198,10 @@ HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
|
|||||||
tmp = hdma->Instance->CCR;
|
tmp = hdma->Instance->CCR;
|
||||||
|
|
||||||
/* Clear PL, MSIZE, PSIZE, MINC, PINC, CIRC and DIR bits */
|
/* Clear PL, MSIZE, PSIZE, MINC, PINC, CIRC and DIR bits */
|
||||||
tmp &= ((uint32_t)~(DMA_CCR_PL | DMA_CCR_MSIZE | DMA_CCR_PSIZE | \
|
tmp &= ((uint32_t) ~(DMA_CCR_PL | DMA_CCR_MSIZE | DMA_CCR_PSIZE | DMA_CCR_MINC | DMA_CCR_PINC | DMA_CCR_CIRC | DMA_CCR_DIR));
|
||||||
DMA_CCR_MINC | DMA_CCR_PINC | DMA_CCR_CIRC | \
|
|
||||||
DMA_CCR_DIR));
|
|
||||||
|
|
||||||
/* Prepare the DMA Channel configuration */
|
/* Prepare the DMA Channel configuration */
|
||||||
tmp |= hdma->Init.Direction |
|
tmp |= hdma->Init.Direction | hdma->Init.PeriphInc | hdma->Init.MemInc | hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment | hdma->Init.Mode | hdma->Init.Priority;
|
||||||
hdma->Init.PeriphInc | hdma->Init.MemInc |
|
|
||||||
hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment |
|
|
||||||
hdma->Init.Mode | hdma->Init.Priority;
|
|
||||||
|
|
||||||
/* Write to DMA Channel CR register */
|
/* Write to DMA Channel CR register */
|
||||||
hdma->Instance->CCR = tmp;
|
hdma->Instance->CCR = tmp;
|
||||||
@@ -233,11 +223,9 @@ HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
|
|||||||
* the configuration information for the specified DMA Channel.
|
* the configuration information for the specified DMA Channel.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
|
HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma) {
|
||||||
{
|
|
||||||
/* Check the DMA handle allocation */
|
/* Check the DMA handle allocation */
|
||||||
if(hdma == NULL)
|
if (hdma == NULL) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,16 +247,13 @@ HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
|
|||||||
/* Reset DMA Channel memory address register */
|
/* Reset DMA Channel memory address register */
|
||||||
hdma->Instance->CMAR = 0U;
|
hdma->Instance->CMAR = 0U;
|
||||||
|
|
||||||
#if defined (STM32F101xE) || defined (STM32F101xG) || defined (STM32F103xE) || defined (STM32F103xG) || defined (STM32F100xE) || defined (STM32F105xC) || defined (STM32F107xC)
|
#if defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F100xE) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
/* calculation of the channel index */
|
/* calculation of the channel index */
|
||||||
if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1))
|
if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1)) {
|
||||||
{
|
|
||||||
/* DMA1 */
|
/* DMA1 */
|
||||||
hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2;
|
hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2;
|
||||||
hdma->DmaBaseAddress = DMA1;
|
hdma->DmaBaseAddress = DMA1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* DMA2 */
|
/* DMA2 */
|
||||||
hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA2_Channel1) / ((uint32_t)DMA2_Channel2 - (uint32_t)DMA2_Channel1)) << 2;
|
hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA2_Channel1) / ((uint32_t)DMA2_Channel2 - (uint32_t)DMA2_Channel1)) << 2;
|
||||||
hdma->DmaBaseAddress = DMA2;
|
hdma->DmaBaseAddress = DMA2;
|
||||||
@@ -332,8 +317,7 @@ HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
|
|||||||
* @param DataLength: The length of data to be transferred from source to destination
|
* @param DataLength: The length of data to be transferred from source to destination
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
|
HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -342,8 +326,7 @@ HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, ui
|
|||||||
/* Process locked */
|
/* Process locked */
|
||||||
__HAL_LOCK(hdma);
|
__HAL_LOCK(hdma);
|
||||||
|
|
||||||
if(HAL_DMA_STATE_READY == hdma->State)
|
if (HAL_DMA_STATE_READY == hdma->State) {
|
||||||
{
|
|
||||||
/* Change DMA peripheral state */
|
/* Change DMA peripheral state */
|
||||||
hdma->State = HAL_DMA_STATE_BUSY;
|
hdma->State = HAL_DMA_STATE_BUSY;
|
||||||
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
|
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
|
||||||
@@ -356,9 +339,7 @@ HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, ui
|
|||||||
|
|
||||||
/* Enable the Peripheral */
|
/* Enable the Peripheral */
|
||||||
__HAL_DMA_ENABLE(hdma);
|
__HAL_DMA_ENABLE(hdma);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Process Unlocked */
|
/* Process Unlocked */
|
||||||
__HAL_UNLOCK(hdma);
|
__HAL_UNLOCK(hdma);
|
||||||
status = HAL_BUSY;
|
status = HAL_BUSY;
|
||||||
@@ -375,8 +356,7 @@ HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, ui
|
|||||||
* @param DataLength: The length of data to be transferred from source to destination
|
* @param DataLength: The length of data to be transferred from source to destination
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
|
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -385,8 +365,7 @@ HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress,
|
|||||||
/* Process locked */
|
/* Process locked */
|
||||||
__HAL_LOCK(hdma);
|
__HAL_LOCK(hdma);
|
||||||
|
|
||||||
if(HAL_DMA_STATE_READY == hdma->State)
|
if (HAL_DMA_STATE_READY == hdma->State) {
|
||||||
{
|
|
||||||
/* Change DMA peripheral state */
|
/* Change DMA peripheral state */
|
||||||
hdma->State = HAL_DMA_STATE_BUSY;
|
hdma->State = HAL_DMA_STATE_BUSY;
|
||||||
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
|
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
|
||||||
@@ -399,21 +378,16 @@ HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress,
|
|||||||
|
|
||||||
/* Enable the transfer complete interrupt */
|
/* Enable the transfer complete interrupt */
|
||||||
/* Enable the transfer Error interrupt */
|
/* Enable the transfer Error interrupt */
|
||||||
if(NULL != hdma->XferHalfCpltCallback)
|
if (NULL != hdma->XferHalfCpltCallback) {
|
||||||
{
|
|
||||||
/* Enable the Half transfer complete interrupt as well */
|
/* Enable the Half transfer complete interrupt as well */
|
||||||
__HAL_DMA_ENABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
|
__HAL_DMA_ENABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
|
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
|
||||||
__HAL_DMA_ENABLE_IT(hdma, (DMA_IT_TC | DMA_IT_TE));
|
__HAL_DMA_ENABLE_IT(hdma, (DMA_IT_TC | DMA_IT_TE));
|
||||||
}
|
}
|
||||||
/* Enable the Peripheral */
|
/* Enable the Peripheral */
|
||||||
__HAL_DMA_ENABLE(hdma);
|
__HAL_DMA_ENABLE(hdma);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Process Unlocked */
|
/* Process Unlocked */
|
||||||
__HAL_UNLOCK(hdma);
|
__HAL_UNLOCK(hdma);
|
||||||
|
|
||||||
@@ -429,8 +403,7 @@ HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress,
|
|||||||
* the configuration information for the specified DMA Channel.
|
* the configuration information for the specified DMA Channel.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
|
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
/* Disable DMA IT */
|
/* Disable DMA IT */
|
||||||
@@ -457,19 +430,15 @@ HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
|
|||||||
* the configuration information for the specified DMA Channel.
|
* the configuration information for the specified DMA Channel.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
|
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
if(HAL_DMA_STATE_BUSY != hdma->State)
|
if (HAL_DMA_STATE_BUSY != hdma->State) {
|
||||||
{
|
|
||||||
/* no transfer ongoing */
|
/* no transfer ongoing */
|
||||||
hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
|
hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
|
||||||
|
|
||||||
status = HAL_ERROR;
|
status = HAL_ERROR;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Disable DMA IT */
|
/* Disable DMA IT */
|
||||||
__HAL_DMA_DISABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
|
__HAL_DMA_DISABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
|
||||||
|
|
||||||
@@ -486,8 +455,7 @@ HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
|
|||||||
__HAL_UNLOCK(hdma);
|
__HAL_UNLOCK(hdma);
|
||||||
|
|
||||||
/* Call User Abort callback */
|
/* Call User Abort callback */
|
||||||
if(hdma->XferAbortCallback != NULL)
|
if (hdma->XferAbortCallback != NULL) {
|
||||||
{
|
|
||||||
hdma->XferAbortCallback(hdma);
|
hdma->XferAbortCallback(hdma);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -502,13 +470,11 @@ HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
|
|||||||
* @param Timeout: Timeout duration.
|
* @param Timeout: Timeout duration.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout)
|
HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout) {
|
||||||
{
|
|
||||||
uint32_t temp;
|
uint32_t temp;
|
||||||
uint32_t tickstart = 0U;
|
uint32_t tickstart = 0U;
|
||||||
|
|
||||||
if(HAL_DMA_STATE_BUSY != hdma->State)
|
if (HAL_DMA_STATE_BUSY != hdma->State) {
|
||||||
{
|
|
||||||
/* no transfer ongoing */
|
/* no transfer ongoing */
|
||||||
hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
|
hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
|
||||||
__HAL_UNLOCK(hdma);
|
__HAL_UNLOCK(hdma);
|
||||||
@@ -516,20 +482,16 @@ HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t Comp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Polling mode not supported in circular mode */
|
/* Polling mode not supported in circular mode */
|
||||||
if (RESET != (hdma->Instance->CCR & DMA_CCR_CIRC))
|
if (RESET != (hdma->Instance->CCR & DMA_CCR_CIRC)) {
|
||||||
{
|
|
||||||
hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
|
hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the level transfer complete flag */
|
/* Get the level transfer complete flag */
|
||||||
if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
|
if (CompleteLevel == HAL_DMA_FULL_TRANSFER) {
|
||||||
{
|
|
||||||
/* Transfer Complete flag */
|
/* Transfer Complete flag */
|
||||||
temp = __HAL_DMA_GET_TC_FLAG_INDEX(hdma);
|
temp = __HAL_DMA_GET_TC_FLAG_INDEX(hdma);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Half Transfer Complete flag */
|
/* Half Transfer Complete flag */
|
||||||
temp = __HAL_DMA_GET_HT_FLAG_INDEX(hdma);
|
temp = __HAL_DMA_GET_HT_FLAG_INDEX(hdma);
|
||||||
}
|
}
|
||||||
@@ -537,10 +499,8 @@ HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t Comp
|
|||||||
/* Get tick */
|
/* Get tick */
|
||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
while(__HAL_DMA_GET_FLAG(hdma, temp) == RESET)
|
while (__HAL_DMA_GET_FLAG(hdma, temp) == RESET) {
|
||||||
{
|
if ((__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET)) {
|
||||||
if((__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET))
|
|
||||||
{
|
|
||||||
/* When a DMA transfer error occurs */
|
/* When a DMA transfer error occurs */
|
||||||
/* A hardware clear of its EN bits is performed */
|
/* A hardware clear of its EN bits is performed */
|
||||||
/* Clear all flags */
|
/* Clear all flags */
|
||||||
@@ -550,7 +510,7 @@ HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t Comp
|
|||||||
SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TE);
|
SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TE);
|
||||||
|
|
||||||
/* Change the DMA state */
|
/* Change the DMA state */
|
||||||
hdma->State= HAL_DMA_STATE_READY;
|
hdma->State = HAL_DMA_STATE_READY;
|
||||||
|
|
||||||
/* Process Unlocked */
|
/* Process Unlocked */
|
||||||
__HAL_UNLOCK(hdma);
|
__HAL_UNLOCK(hdma);
|
||||||
@@ -558,10 +518,8 @@ HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t Comp
|
|||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
/* Check for the Timeout */
|
/* Check for the Timeout */
|
||||||
if(Timeout != HAL_MAX_DELAY)
|
if (Timeout != HAL_MAX_DELAY) {
|
||||||
{
|
if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout)) {
|
||||||
if((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout))
|
|
||||||
{
|
|
||||||
/* Update error code */
|
/* Update error code */
|
||||||
SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TIMEOUT);
|
SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TIMEOUT);
|
||||||
|
|
||||||
@@ -576,17 +534,14 @@ HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t Comp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
|
if (CompleteLevel == HAL_DMA_FULL_TRANSFER) {
|
||||||
{
|
|
||||||
/* Clear the transfer complete flag */
|
/* Clear the transfer complete flag */
|
||||||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
|
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
|
||||||
|
|
||||||
/* The selected Channelx EN bit is cleared (DMA is disabled and
|
/* The selected Channelx EN bit is cleared (DMA is disabled and
|
||||||
all transfers are complete) */
|
all transfers are complete) */
|
||||||
hdma->State = HAL_DMA_STATE_READY;
|
hdma->State = HAL_DMA_STATE_READY;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Clear the half transfer complete flag */
|
/* Clear the half transfer complete flag */
|
||||||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
|
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
|
||||||
}
|
}
|
||||||
@@ -603,17 +558,14 @@ HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t Comp
|
|||||||
* the configuration information for the specified DMA Channel.
|
* the configuration information for the specified DMA Channel.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
|
void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma) {
|
||||||
{
|
|
||||||
uint32_t flag_it = hdma->DmaBaseAddress->ISR;
|
uint32_t flag_it = hdma->DmaBaseAddress->ISR;
|
||||||
uint32_t source_it = hdma->Instance->CCR;
|
uint32_t source_it = hdma->Instance->CCR;
|
||||||
|
|
||||||
/* Half Transfer Complete Interrupt management ******************************/
|
/* Half Transfer Complete Interrupt management ******************************/
|
||||||
if (((flag_it & (DMA_FLAG_HT1 << hdma->ChannelIndex)) != RESET) && ((source_it & DMA_IT_HT) != RESET))
|
if (((flag_it & (DMA_FLAG_HT1 << hdma->ChannelIndex)) != RESET) && ((source_it & DMA_IT_HT) != RESET)) {
|
||||||
{
|
|
||||||
/* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */
|
/* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */
|
||||||
if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U)
|
if ((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U) {
|
||||||
{
|
|
||||||
/* Disable the half transfer interrupt */
|
/* Disable the half transfer interrupt */
|
||||||
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
|
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
|
||||||
}
|
}
|
||||||
@@ -623,18 +575,15 @@ void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
|
|||||||
/* DMA peripheral state is not updated in Half Transfer */
|
/* DMA peripheral state is not updated in Half Transfer */
|
||||||
/* but in Transfer Complete case */
|
/* but in Transfer Complete case */
|
||||||
|
|
||||||
if(hdma->XferHalfCpltCallback != NULL)
|
if (hdma->XferHalfCpltCallback != NULL) {
|
||||||
{
|
|
||||||
/* Half transfer callback */
|
/* Half transfer callback */
|
||||||
hdma->XferHalfCpltCallback(hdma);
|
hdma->XferHalfCpltCallback(hdma);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Transfer Complete Interrupt management ***********************************/
|
/* Transfer Complete Interrupt management ***********************************/
|
||||||
else if (((flag_it & (DMA_FLAG_TC1 << hdma->ChannelIndex)) != RESET) && ((source_it & DMA_IT_TC) != RESET))
|
else if (((flag_it & (DMA_FLAG_TC1 << hdma->ChannelIndex)) != RESET) && ((source_it & DMA_IT_TC) != RESET)) {
|
||||||
{
|
if ((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U) {
|
||||||
if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U)
|
|
||||||
{
|
|
||||||
/* Disable the transfer complete and error interrupt */
|
/* Disable the transfer complete and error interrupt */
|
||||||
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_TE | DMA_IT_TC);
|
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_TE | DMA_IT_TC);
|
||||||
|
|
||||||
@@ -647,16 +596,14 @@ void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
|
|||||||
/* Process Unlocked */
|
/* Process Unlocked */
|
||||||
__HAL_UNLOCK(hdma);
|
__HAL_UNLOCK(hdma);
|
||||||
|
|
||||||
if(hdma->XferCpltCallback != NULL)
|
if (hdma->XferCpltCallback != NULL) {
|
||||||
{
|
|
||||||
/* Transfer complete callback */
|
/* Transfer complete callback */
|
||||||
hdma->XferCpltCallback(hdma);
|
hdma->XferCpltCallback(hdma);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Transfer Error Interrupt management **************************************/
|
/* Transfer Error Interrupt management **************************************/
|
||||||
else if (( RESET != (flag_it & (DMA_FLAG_TE1 << hdma->ChannelIndex))) && (RESET != (source_it & DMA_IT_TE)))
|
else if ((RESET != (flag_it & (DMA_FLAG_TE1 << hdma->ChannelIndex))) && (RESET != (source_it & DMA_IT_TE))) {
|
||||||
{
|
|
||||||
/* When a DMA transfer error occurs */
|
/* When a DMA transfer error occurs */
|
||||||
/* A hardware clear of its EN bits is performed */
|
/* A hardware clear of its EN bits is performed */
|
||||||
/* Disable ALL DMA IT */
|
/* Disable ALL DMA IT */
|
||||||
@@ -674,8 +621,7 @@ void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
|
|||||||
/* Process Unlocked */
|
/* Process Unlocked */
|
||||||
__HAL_UNLOCK(hdma);
|
__HAL_UNLOCK(hdma);
|
||||||
|
|
||||||
if (hdma->XferErrorCallback != NULL)
|
if (hdma->XferErrorCallback != NULL) {
|
||||||
{
|
|
||||||
/* Transfer error callback */
|
/* Transfer error callback */
|
||||||
hdma->XferErrorCallback(hdma);
|
hdma->XferErrorCallback(hdma);
|
||||||
}
|
}
|
||||||
@@ -693,17 +639,14 @@ void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
|
|||||||
* a DMA_HandleTypeDef structure as parameter.
|
* a DMA_HandleTypeDef structure as parameter.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (* pCallback)( DMA_HandleTypeDef * _hdma))
|
HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (*pCallback)(DMA_HandleTypeDef *_hdma)) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
/* Process locked */
|
/* Process locked */
|
||||||
__HAL_LOCK(hdma);
|
__HAL_LOCK(hdma);
|
||||||
|
|
||||||
if(HAL_DMA_STATE_READY == hdma->State)
|
if (HAL_DMA_STATE_READY == hdma->State) {
|
||||||
{
|
switch (CallbackID) {
|
||||||
switch (CallbackID)
|
|
||||||
{
|
|
||||||
case HAL_DMA_XFER_CPLT_CB_ID:
|
case HAL_DMA_XFER_CPLT_CB_ID:
|
||||||
hdma->XferCpltCallback = pCallback;
|
hdma->XferCpltCallback = pCallback;
|
||||||
break;
|
break;
|
||||||
@@ -724,9 +667,7 @@ HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_Call
|
|||||||
status = HAL_ERROR;
|
status = HAL_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
status = HAL_ERROR;
|
status = HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -744,17 +685,14 @@ HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_Call
|
|||||||
* a HAL_DMA_CallbackIDTypeDef ENUM as parameter.
|
* a HAL_DMA_CallbackIDTypeDef ENUM as parameter.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID)
|
HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
/* Process locked */
|
/* Process locked */
|
||||||
__HAL_LOCK(hdma);
|
__HAL_LOCK(hdma);
|
||||||
|
|
||||||
if(HAL_DMA_STATE_READY == hdma->State)
|
if (HAL_DMA_STATE_READY == hdma->State) {
|
||||||
{
|
switch (CallbackID) {
|
||||||
switch (CallbackID)
|
|
||||||
{
|
|
||||||
case HAL_DMA_XFER_CPLT_CB_ID:
|
case HAL_DMA_XFER_CPLT_CB_ID:
|
||||||
hdma->XferCpltCallback = NULL;
|
hdma->XferCpltCallback = NULL;
|
||||||
break;
|
break;
|
||||||
@@ -782,9 +720,7 @@ HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_Ca
|
|||||||
status = HAL_ERROR;
|
status = HAL_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
status = HAL_ERROR;
|
status = HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -820,8 +756,7 @@ HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_Ca
|
|||||||
* the configuration information for the specified DMA Channel.
|
* the configuration information for the specified DMA Channel.
|
||||||
* @retval HAL state
|
* @retval HAL state
|
||||||
*/
|
*/
|
||||||
HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma)
|
HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma) {
|
||||||
{
|
|
||||||
/* Return DMA handle state */
|
/* Return DMA handle state */
|
||||||
return hdma->State;
|
return hdma->State;
|
||||||
}
|
}
|
||||||
@@ -832,10 +767,7 @@ HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma)
|
|||||||
* the configuration information for the specified DMA Channel.
|
* the configuration information for the specified DMA Channel.
|
||||||
* @retval DMA Error Code
|
* @retval DMA Error Code
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
|
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma) { return hdma->ErrorCode; }
|
||||||
{
|
|
||||||
return hdma->ErrorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -858,8 +790,7 @@ uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
|
|||||||
* @param DataLength: The length of data to be transferred from source to destination
|
* @param DataLength: The length of data to be transferred from source to destination
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
|
static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) {
|
||||||
{
|
|
||||||
/* Clear all flags */
|
/* Clear all flags */
|
||||||
hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << hdma->ChannelIndex);
|
hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << hdma->ChannelIndex);
|
||||||
|
|
||||||
@@ -867,8 +798,7 @@ static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t
|
|||||||
hdma->Instance->CNDTR = DataLength;
|
hdma->Instance->CNDTR = DataLength;
|
||||||
|
|
||||||
/* Memory to Peripheral */
|
/* Memory to Peripheral */
|
||||||
if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
|
if ((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH) {
|
||||||
{
|
|
||||||
/* Configure DMA Channel destination address */
|
/* Configure DMA Channel destination address */
|
||||||
hdma->Instance->CPAR = DstAddress;
|
hdma->Instance->CPAR = DstAddress;
|
||||||
|
|
||||||
@@ -876,8 +806,7 @@ static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t
|
|||||||
hdma->Instance->CMAR = SrcAddress;
|
hdma->Instance->CMAR = SrcAddress;
|
||||||
}
|
}
|
||||||
/* Peripheral to Memory */
|
/* Peripheral to Memory */
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Configure DMA Channel source address */
|
/* Configure DMA Channel source address */
|
||||||
hdma->Instance->CPAR = SrcAddress;
|
hdma->Instance->CPAR = SrcAddress;
|
||||||
|
|
||||||
|
|||||||
@@ -181,8 +181,7 @@ extern void FLASH_PageErase(uint32_t PageAddress);
|
|||||||
*
|
*
|
||||||
* @retval HAL_StatusTypeDef HAL Status
|
* @retval HAL_StatusTypeDef HAL Status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
|
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_ERROR;
|
HAL_StatusTypeDef status = HAL_ERROR;
|
||||||
uint8_t index = 0;
|
uint8_t index = 0;
|
||||||
uint8_t nbiterations = 0;
|
uint8_t nbiterations = 0;
|
||||||
@@ -195,45 +194,34 @@ HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint
|
|||||||
assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
|
assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
|
||||||
|
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
if(Address <= FLASH_BANK1_END)
|
if (Address <= FLASH_BANK1_END) {
|
||||||
{
|
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
|
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
status = FLASH_WaitForLastOperationBank2(FLASH_TIMEOUT_VALUE);
|
status = FLASH_WaitForLastOperationBank2(FLASH_TIMEOUT_VALUE);
|
||||||
}
|
}
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
|
|
||||||
if(status == HAL_OK)
|
if (status == HAL_OK) {
|
||||||
{
|
if (TypeProgram == FLASH_TYPEPROGRAM_HALFWORD) {
|
||||||
if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD)
|
|
||||||
{
|
|
||||||
/* Program halfword (16-bit) at a specified address. */
|
/* Program halfword (16-bit) at a specified address. */
|
||||||
nbiterations = 1U;
|
nbiterations = 1U;
|
||||||
}
|
} else if (TypeProgram == FLASH_TYPEPROGRAM_WORD) {
|
||||||
else if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
|
|
||||||
{
|
|
||||||
/* Program word (32-bit = 2*16-bit) at a specified address. */
|
/* Program word (32-bit = 2*16-bit) at a specified address. */
|
||||||
nbiterations = 2U;
|
nbiterations = 2U;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Program double word (64-bit = 4*16-bit) at a specified address. */
|
/* Program double word (64-bit = 4*16-bit) at a specified address. */
|
||||||
nbiterations = 4U;
|
nbiterations = 4U;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (index = 0U; index < nbiterations; index++)
|
for (index = 0U; index < nbiterations; index++) {
|
||||||
{
|
FLASH_Program_HalfWord((Address + (2U * index)), (uint16_t)(Data >> (16U * index)));
|
||||||
FLASH_Program_HalfWord((Address + (2U*index)), (uint16_t)(Data >> (16U*index)));
|
|
||||||
|
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
if(Address <= FLASH_BANK1_END)
|
if (Address <= FLASH_BANK1_END) {
|
||||||
{
|
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
|
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
|
||||||
@@ -241,9 +229,7 @@ HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint
|
|||||||
/* If the program operation is completed, disable the PG Bit */
|
/* If the program operation is completed, disable the PG Bit */
|
||||||
CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
|
CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
status = FLASH_WaitForLastOperationBank2(FLASH_TIMEOUT_VALUE);
|
status = FLASH_WaitForLastOperationBank2(FLASH_TIMEOUT_VALUE);
|
||||||
|
|
||||||
@@ -252,8 +238,7 @@ HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint
|
|||||||
}
|
}
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
/* In case of error, stop programation procedure */
|
/* In case of error, stop programation procedure */
|
||||||
if (status != HAL_OK)
|
if (status != HAL_OK) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -280,8 +265,7 @@ HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint
|
|||||||
*
|
*
|
||||||
* @retval HAL_StatusTypeDef HAL Status
|
* @retval HAL_StatusTypeDef HAL Status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
|
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
/* Process Locked */
|
/* Process Locked */
|
||||||
@@ -293,18 +277,15 @@ HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, u
|
|||||||
|
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
/* If procedure already ongoing, reject the next one */
|
/* If procedure already ongoing, reject the next one */
|
||||||
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
|
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Address <= FLASH_BANK1_END)
|
if (Address <= FLASH_BANK1_END) {
|
||||||
{
|
|
||||||
/* Enable End of FLASH Operation and Error source interrupts */
|
/* Enable End of FLASH Operation and Error source interrupts */
|
||||||
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK1 | FLASH_IT_ERR_BANK1);
|
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK1 | FLASH_IT_ERR_BANK1);
|
||||||
|
|
||||||
}else
|
} else {
|
||||||
{
|
|
||||||
/* Enable End of FLASH Operation and Error source interrupts */
|
/* Enable End of FLASH Operation and Error source interrupts */
|
||||||
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2);
|
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2);
|
||||||
}
|
}
|
||||||
@@ -316,20 +297,15 @@ HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, u
|
|||||||
pFlash.Address = Address;
|
pFlash.Address = Address;
|
||||||
pFlash.Data = Data;
|
pFlash.Data = Data;
|
||||||
|
|
||||||
if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD)
|
if (TypeProgram == FLASH_TYPEPROGRAM_HALFWORD) {
|
||||||
{
|
|
||||||
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMHALFWORD;
|
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMHALFWORD;
|
||||||
/* Program halfword (16-bit) at a specified address. */
|
/* Program halfword (16-bit) at a specified address. */
|
||||||
pFlash.DataRemaining = 1U;
|
pFlash.DataRemaining = 1U;
|
||||||
}
|
} else if (TypeProgram == FLASH_TYPEPROGRAM_WORD) {
|
||||||
else if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
|
|
||||||
{
|
|
||||||
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMWORD;
|
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMWORD;
|
||||||
/* Program word (32-bit : 2*16-bit) at a specified address. */
|
/* Program word (32-bit : 2*16-bit) at a specified address. */
|
||||||
pFlash.DataRemaining = 2U;
|
pFlash.DataRemaining = 2U;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMDOUBLEWORD;
|
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMDOUBLEWORD;
|
||||||
/* Program double word (64-bit : 4*16-bit) at a specified address. */
|
/* Program double word (64-bit : 4*16-bit) at a specified address. */
|
||||||
pFlash.DataRemaining = 4U;
|
pFlash.DataRemaining = 4U;
|
||||||
@@ -345,16 +321,14 @@ HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, u
|
|||||||
* @brief This function handles FLASH interrupt request.
|
* @brief This function handles FLASH interrupt request.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_FLASH_IRQHandler(void)
|
void HAL_FLASH_IRQHandler(void) {
|
||||||
{
|
|
||||||
uint32_t addresstmp = 0U;
|
uint32_t addresstmp = 0U;
|
||||||
|
|
||||||
/* Check FLASH operation error flags */
|
/* Check FLASH operation error flags */
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK1) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK1) || \
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK1) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK1) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2)))
|
||||||
(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2)))
|
|
||||||
#else
|
#else
|
||||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) ||__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
{
|
{
|
||||||
/* Return the faulty address */
|
/* Return the faulty address */
|
||||||
@@ -374,28 +348,23 @@ void HAL_FLASH_IRQHandler(void)
|
|||||||
|
|
||||||
/* Check FLASH End of Operation flag */
|
/* Check FLASH End of Operation flag */
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK1))
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK1)) {
|
||||||
{
|
|
||||||
/* Clear FLASH End of Operation pending bit */
|
/* Clear FLASH End of Operation pending bit */
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK1);
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK1);
|
||||||
#else
|
#else
|
||||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP)) {
|
||||||
{
|
|
||||||
/* Clear FLASH End of Operation pending bit */
|
/* Clear FLASH End of Operation pending bit */
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
|
|
||||||
/* Process can continue only if no error detected */
|
/* Process can continue only if no error detected */
|
||||||
if(pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
|
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE) {
|
||||||
{
|
if (pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE) {
|
||||||
if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
|
|
||||||
{
|
|
||||||
/* Nb of pages to erased can be decreased */
|
/* Nb of pages to erased can be decreased */
|
||||||
pFlash.DataRemaining--;
|
pFlash.DataRemaining--;
|
||||||
|
|
||||||
/* Check if there are still pages to erase */
|
/* Check if there are still pages to erase */
|
||||||
if(pFlash.DataRemaining != 0U)
|
if (pFlash.DataRemaining != 0U) {
|
||||||
{
|
|
||||||
addresstmp = pFlash.Address;
|
addresstmp = pFlash.Address;
|
||||||
/*Indicate user which sector has been erased */
|
/*Indicate user which sector has been erased */
|
||||||
HAL_FLASH_EndOfOperationCallback(addresstmp);
|
HAL_FLASH_EndOfOperationCallback(addresstmp);
|
||||||
@@ -408,9 +377,7 @@ void HAL_FLASH_IRQHandler(void)
|
|||||||
CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
|
CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
|
||||||
|
|
||||||
FLASH_PageErase(addresstmp);
|
FLASH_PageErase(addresstmp);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* No more pages to Erase, user callback can be called. */
|
/* No more pages to Erase, user callback can be called. */
|
||||||
/* Reset Sector and stop Erase pages procedure */
|
/* Reset Sector and stop Erase pages procedure */
|
||||||
pFlash.Address = addresstmp = 0xFFFFFFFFU;
|
pFlash.Address = addresstmp = 0xFFFFFFFFU;
|
||||||
@@ -418,16 +385,13 @@ void HAL_FLASH_IRQHandler(void)
|
|||||||
/* FLASH EOP interrupt user callback */
|
/* FLASH EOP interrupt user callback */
|
||||||
HAL_FLASH_EndOfOperationCallback(addresstmp);
|
HAL_FLASH_EndOfOperationCallback(addresstmp);
|
||||||
}
|
}
|
||||||
}
|
} else if (pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE) {
|
||||||
else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
|
|
||||||
{
|
|
||||||
/* Operation is completed, disable the MER Bit */
|
/* Operation is completed, disable the MER Bit */
|
||||||
CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
|
CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
|
||||||
|
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
/* Stop Mass Erase procedure if no pending mass erase on other bank */
|
/* Stop Mass Erase procedure if no pending mass erase on other bank */
|
||||||
if (HAL_IS_BIT_CLR(FLASH->CR2, FLASH_CR2_MER))
|
if (HAL_IS_BIT_CLR(FLASH->CR2, FLASH_CR2_MER)) {
|
||||||
{
|
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
/* MassErase ended. Return the selected bank */
|
/* MassErase ended. Return the selected bank */
|
||||||
/* FLASH EOP interrupt user callback */
|
/* FLASH EOP interrupt user callback */
|
||||||
@@ -439,14 +403,12 @@ void HAL_FLASH_IRQHandler(void)
|
|||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
}
|
}
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Nb of 16-bit data to program can be decreased */
|
/* Nb of 16-bit data to program can be decreased */
|
||||||
pFlash.DataRemaining--;
|
pFlash.DataRemaining--;
|
||||||
|
|
||||||
/* Check if there are still 16-bit data to program */
|
/* Check if there are still 16-bit data to program */
|
||||||
if(pFlash.DataRemaining != 0U)
|
if (pFlash.DataRemaining != 0U) {
|
||||||
{
|
|
||||||
/* Increment address to 16-bit */
|
/* Increment address to 16-bit */
|
||||||
pFlash.Address += 2U;
|
pFlash.Address += 2U;
|
||||||
addresstmp = pFlash.Address;
|
addresstmp = pFlash.Address;
|
||||||
@@ -459,21 +421,14 @@ void HAL_FLASH_IRQHandler(void)
|
|||||||
|
|
||||||
/*Program halfword (16-bit) at a specified address.*/
|
/*Program halfword (16-bit) at a specified address.*/
|
||||||
FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data);
|
FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Program ended. Return the selected address */
|
/* Program ended. Return the selected address */
|
||||||
/* FLASH EOP interrupt user callback */
|
/* FLASH EOP interrupt user callback */
|
||||||
if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD)
|
if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD) {
|
||||||
{
|
|
||||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||||
}
|
} else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD) {
|
||||||
else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD)
|
|
||||||
{
|
|
||||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address - 2U);
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address - 2U);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address - 6U);
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address - 6U);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,22 +442,18 @@ void HAL_FLASH_IRQHandler(void)
|
|||||||
|
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
/* Check FLASH End of Operation flag */
|
/* Check FLASH End of Operation flag */
|
||||||
if(__HAL_FLASH_GET_FLAG( FLASH_FLAG_EOP_BANK2))
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK2)) {
|
||||||
{
|
|
||||||
/* Clear FLASH End of Operation pending bit */
|
/* Clear FLASH End of Operation pending bit */
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2);
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2);
|
||||||
|
|
||||||
/* Process can continue only if no error detected */
|
/* Process can continue only if no error detected */
|
||||||
if(pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
|
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE) {
|
||||||
{
|
if (pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE) {
|
||||||
if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
|
|
||||||
{
|
|
||||||
/* Nb of pages to erased can be decreased */
|
/* Nb of pages to erased can be decreased */
|
||||||
pFlash.DataRemaining--;
|
pFlash.DataRemaining--;
|
||||||
|
|
||||||
/* Check if there are still pages to erase*/
|
/* Check if there are still pages to erase*/
|
||||||
if(pFlash.DataRemaining != 0U)
|
if (pFlash.DataRemaining != 0U) {
|
||||||
{
|
|
||||||
/* Indicate user which page address has been erased*/
|
/* Indicate user which page address has been erased*/
|
||||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||||
|
|
||||||
@@ -514,9 +465,7 @@ void HAL_FLASH_IRQHandler(void)
|
|||||||
CLEAR_BIT(FLASH->CR2, FLASH_CR2_PER);
|
CLEAR_BIT(FLASH->CR2, FLASH_CR2_PER);
|
||||||
|
|
||||||
FLASH_PageErase(addresstmp);
|
FLASH_PageErase(addresstmp);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/*No more pages to Erase*/
|
/*No more pages to Erase*/
|
||||||
|
|
||||||
/*Reset Address and stop Erase pages procedure*/
|
/*Reset Address and stop Erase pages procedure*/
|
||||||
@@ -526,29 +475,23 @@ void HAL_FLASH_IRQHandler(void)
|
|||||||
/* FLASH EOP interrupt user callback */
|
/* FLASH EOP interrupt user callback */
|
||||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||||
}
|
}
|
||||||
}
|
} else if (pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE) {
|
||||||
else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
|
|
||||||
{
|
|
||||||
/* Operation is completed, disable the MER Bit */
|
/* Operation is completed, disable the MER Bit */
|
||||||
CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
|
CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
|
||||||
|
|
||||||
if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_MER))
|
if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_MER)) {
|
||||||
{
|
|
||||||
/* MassErase ended. Return the selected bank*/
|
/* MassErase ended. Return the selected bank*/
|
||||||
/* FLASH EOP interrupt user callback */
|
/* FLASH EOP interrupt user callback */
|
||||||
HAL_FLASH_EndOfOperationCallback(0U);
|
HAL_FLASH_EndOfOperationCallback(0U);
|
||||||
|
|
||||||
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Nb of 16-bit data to program can be decreased */
|
/* Nb of 16-bit data to program can be decreased */
|
||||||
pFlash.DataRemaining--;
|
pFlash.DataRemaining--;
|
||||||
|
|
||||||
/* Check if there are still 16-bit data to program */
|
/* Check if there are still 16-bit data to program */
|
||||||
if(pFlash.DataRemaining != 0U)
|
if (pFlash.DataRemaining != 0U) {
|
||||||
{
|
|
||||||
/* Increment address to 16-bit */
|
/* Increment address to 16-bit */
|
||||||
pFlash.Address += 2U;
|
pFlash.Address += 2U;
|
||||||
addresstmp = pFlash.Address;
|
addresstmp = pFlash.Address;
|
||||||
@@ -561,22 +504,15 @@ void HAL_FLASH_IRQHandler(void)
|
|||||||
|
|
||||||
/*Program halfword (16-bit) at a specified address.*/
|
/*Program halfword (16-bit) at a specified address.*/
|
||||||
FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data);
|
FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/*Program ended. Return the selected address*/
|
/*Program ended. Return the selected address*/
|
||||||
/* FLASH EOP interrupt user callback */
|
/* FLASH EOP interrupt user callback */
|
||||||
if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD)
|
if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD) {
|
||||||
{
|
|
||||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||||
}
|
} else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD) {
|
||||||
else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD)
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address - 2U);
|
||||||
{
|
} else {
|
||||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address-2U);
|
HAL_FLASH_EndOfOperationCallback(pFlash.Address - 6U);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address-6U);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset Address and stop Program procedure*/
|
/* Reset Address and stop Program procedure*/
|
||||||
@@ -588,8 +524,7 @@ void HAL_FLASH_IRQHandler(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE)
|
if (pFlash.ProcedureOnGoing == FLASH_PROC_NONE) {
|
||||||
{
|
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
/* Operation is completed, disable the PG, PER and MER Bits for both bank */
|
/* Operation is completed, disable the PG, PER and MER Bits for both bank */
|
||||||
CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_PER | FLASH_CR_MER));
|
CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_PER | FLASH_CR_MER));
|
||||||
@@ -619,8 +554,7 @@ void HAL_FLASH_IRQHandler(void)
|
|||||||
* - Program: Address which was selected for data program
|
* - Program: Address which was selected for data program
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
__weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
|
__weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue) {
|
||||||
{
|
|
||||||
/* Prevent unused argument(s) compilation warning */
|
/* Prevent unused argument(s) compilation warning */
|
||||||
UNUSED(ReturnValue);
|
UNUSED(ReturnValue);
|
||||||
|
|
||||||
@@ -637,8 +571,7 @@ __weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
|
|||||||
* - Program: Address which was selected for data program
|
* - Program: Address which was selected for data program
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
__weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
|
__weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue) {
|
||||||
{
|
|
||||||
/* Prevent unused argument(s) compilation warning */
|
/* Prevent unused argument(s) compilation warning */
|
||||||
UNUSED(ReturnValue);
|
UNUSED(ReturnValue);
|
||||||
|
|
||||||
@@ -670,32 +603,27 @@ __weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
|
|||||||
* @brief Unlock the FLASH control register access
|
* @brief Unlock the FLASH control register access
|
||||||
* @retval HAL Status
|
* @retval HAL Status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_FLASH_Unlock(void)
|
HAL_StatusTypeDef HAL_FLASH_Unlock(void) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET)
|
if (READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET) {
|
||||||
{
|
|
||||||
/* Authorize the FLASH Registers access */
|
/* Authorize the FLASH Registers access */
|
||||||
WRITE_REG(FLASH->KEYR, FLASH_KEY1);
|
WRITE_REG(FLASH->KEYR, FLASH_KEY1);
|
||||||
WRITE_REG(FLASH->KEYR, FLASH_KEY2);
|
WRITE_REG(FLASH->KEYR, FLASH_KEY2);
|
||||||
|
|
||||||
/* Verify Flash is unlocked */
|
/* Verify Flash is unlocked */
|
||||||
if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET)
|
if (READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET) {
|
||||||
{
|
|
||||||
status = HAL_ERROR;
|
status = HAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
if(READ_BIT(FLASH->CR2, FLASH_CR2_LOCK) != RESET)
|
if (READ_BIT(FLASH->CR2, FLASH_CR2_LOCK) != RESET) {
|
||||||
{
|
|
||||||
/* Authorize the FLASH BANK2 Registers access */
|
/* Authorize the FLASH BANK2 Registers access */
|
||||||
WRITE_REG(FLASH->KEYR2, FLASH_KEY1);
|
WRITE_REG(FLASH->KEYR2, FLASH_KEY1);
|
||||||
WRITE_REG(FLASH->KEYR2, FLASH_KEY2);
|
WRITE_REG(FLASH->KEYR2, FLASH_KEY2);
|
||||||
|
|
||||||
/* Verify Flash BANK2 is unlocked */
|
/* Verify Flash BANK2 is unlocked */
|
||||||
if(READ_BIT(FLASH->CR2, FLASH_CR2_LOCK) != RESET)
|
if (READ_BIT(FLASH->CR2, FLASH_CR2_LOCK) != RESET) {
|
||||||
{
|
|
||||||
status = HAL_ERROR;
|
status = HAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -708,8 +636,7 @@ HAL_StatusTypeDef HAL_FLASH_Unlock(void)
|
|||||||
* @brief Locks the FLASH control register access
|
* @brief Locks the FLASH control register access
|
||||||
* @retval HAL Status
|
* @retval HAL Status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_FLASH_Lock(void)
|
HAL_StatusTypeDef HAL_FLASH_Lock(void) {
|
||||||
{
|
|
||||||
/* Set the LOCK Bit to lock the FLASH Registers access */
|
/* Set the LOCK Bit to lock the FLASH Registers access */
|
||||||
SET_BIT(FLASH->CR, FLASH_CR_LOCK);
|
SET_BIT(FLASH->CR, FLASH_CR_LOCK);
|
||||||
|
|
||||||
@@ -725,16 +652,12 @@ HAL_StatusTypeDef HAL_FLASH_Lock(void)
|
|||||||
* @brief Unlock the FLASH Option Control Registers access.
|
* @brief Unlock the FLASH Option Control Registers access.
|
||||||
* @retval HAL Status
|
* @retval HAL Status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
|
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void) {
|
||||||
{
|
if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_OPTWRE)) {
|
||||||
if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_OPTWRE))
|
|
||||||
{
|
|
||||||
/* Authorizes the Option Byte register programming */
|
/* Authorizes the Option Byte register programming */
|
||||||
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1);
|
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1);
|
||||||
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2);
|
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -745,8 +668,7 @@ HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
|
|||||||
* @brief Lock the FLASH Option Control Registers access.
|
* @brief Lock the FLASH Option Control Registers access.
|
||||||
* @retval HAL Status
|
* @retval HAL Status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
|
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void) {
|
||||||
{
|
|
||||||
/* Clear the OPTWRE Bit to lock the FLASH Option Byte Registers access */
|
/* Clear the OPTWRE Bit to lock the FLASH Option Byte Registers access */
|
||||||
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTWRE);
|
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTWRE);
|
||||||
|
|
||||||
@@ -758,8 +680,7 @@ HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
|
|||||||
* @note This function will reset automatically the MCU.
|
* @note This function will reset automatically the MCU.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_FLASH_OB_Launch(void)
|
void HAL_FLASH_OB_Launch(void) {
|
||||||
{
|
|
||||||
/* Initiates a system reset request to launch the option byte loading */
|
/* Initiates a system reset request to launch the option byte loading */
|
||||||
HAL_NVIC_SystemReset();
|
HAL_NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
@@ -787,10 +708,7 @@ void HAL_FLASH_OB_Launch(void)
|
|||||||
* @retval FLASH_ErrorCode The returned value can be:
|
* @retval FLASH_ErrorCode The returned value can be:
|
||||||
* @ref FLASH_Error_Codes
|
* @ref FLASH_Error_Codes
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_FLASH_GetError(void)
|
uint32_t HAL_FLASH_GetError(void) { return pFlash.ErrorCode; }
|
||||||
{
|
|
||||||
return pFlash.ErrorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -810,28 +728,24 @@ uint32_t HAL_FLASH_GetError(void)
|
|||||||
* @param Data specify the data to be programmed.
|
* @param Data specify the data to be programmed.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data)
|
static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data) {
|
||||||
{
|
|
||||||
/* Clean the error context */
|
/* Clean the error context */
|
||||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||||
|
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
if(Address <= FLASH_BANK1_END)
|
if (Address <= FLASH_BANK1_END) {
|
||||||
{
|
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
/* Proceed to program the new data */
|
/* Proceed to program the new data */
|
||||||
SET_BIT(FLASH->CR, FLASH_CR_PG);
|
SET_BIT(FLASH->CR, FLASH_CR_PG);
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Proceed to program the new data */
|
/* Proceed to program the new data */
|
||||||
SET_BIT(FLASH->CR2, FLASH_CR2_PG);
|
SET_BIT(FLASH->CR2, FLASH_CR2_PG);
|
||||||
}
|
}
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
|
|
||||||
/* Write data in the address */
|
/* Write data in the address */
|
||||||
*(__IO uint16_t*)Address = Data;
|
*(__IO uint16_t *)Address = Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -839,36 +753,28 @@ static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data)
|
|||||||
* @param Timeout maximum flash operation timeout
|
* @param Timeout maximum flash operation timeout
|
||||||
* @retval HAL Status
|
* @retval HAL Status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
|
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout) {
|
||||||
{
|
|
||||||
/* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
|
/* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
|
||||||
Even if the FLASH operation fails, the BUSY flag will be reset and an error
|
Even if the FLASH operation fails, the BUSY flag will be reset and an error
|
||||||
flag will be set */
|
flag will be set */
|
||||||
|
|
||||||
uint32_t tickstart = HAL_GetTick();
|
uint32_t tickstart = HAL_GetTick();
|
||||||
|
|
||||||
while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY))
|
while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY)) {
|
||||||
{
|
if (Timeout != HAL_MAX_DELAY) {
|
||||||
if (Timeout != HAL_MAX_DELAY)
|
if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout)) {
|
||||||
{
|
|
||||||
if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout))
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check FLASH End of Operation flag */
|
/* Check FLASH End of Operation flag */
|
||||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP)) {
|
||||||
{
|
|
||||||
/* Clear FLASH End of Operation pending bit */
|
/* Clear FLASH End of Operation pending bit */
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) ||
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR)) {
|
||||||
__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR) ||
|
|
||||||
__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
|
|
||||||
{
|
|
||||||
/*Save the error code*/
|
/*Save the error code*/
|
||||||
FLASH_SetErrorCode();
|
FLASH_SetErrorCode();
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
@@ -884,34 +790,28 @@ HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
|
|||||||
* @param Timeout maximum flash operation timeout
|
* @param Timeout maximum flash operation timeout
|
||||||
* @retval HAL_StatusTypeDef HAL Status
|
* @retval HAL_StatusTypeDef HAL Status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout)
|
HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout) {
|
||||||
{
|
|
||||||
/* Wait for the FLASH BANK2 operation to complete by polling on BUSY flag to be reset.
|
/* Wait for the FLASH BANK2 operation to complete by polling on BUSY flag to be reset.
|
||||||
Even if the FLASH BANK2 operation fails, the BUSY flag will be reset and an error
|
Even if the FLASH BANK2 operation fails, the BUSY flag will be reset and an error
|
||||||
flag will be set */
|
flag will be set */
|
||||||
|
|
||||||
uint32_t tickstart = HAL_GetTick();
|
uint32_t tickstart = HAL_GetTick();
|
||||||
|
|
||||||
while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY_BANK2))
|
while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY_BANK2)) {
|
||||||
{
|
if (Timeout != HAL_MAX_DELAY) {
|
||||||
if (Timeout != HAL_MAX_DELAY)
|
if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout)) {
|
||||||
{
|
|
||||||
if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout))
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check FLASH End of Operation flag */
|
/* Check FLASH End of Operation flag */
|
||||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK2))
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK2)) {
|
||||||
{
|
|
||||||
/* Clear FLASH End of Operation pending bit */
|
/* Clear FLASH End of Operation pending bit */
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2);
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2))
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2)) {
|
||||||
{
|
|
||||||
/*Save the error code*/
|
/*Save the error code*/
|
||||||
FLASH_SetErrorCode();
|
FLASH_SetErrorCode();
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
@@ -919,7 +819,6 @@ HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout)
|
|||||||
|
|
||||||
/* If there is an error flag set */
|
/* If there is an error flag set */
|
||||||
return HAL_OK;
|
return HAL_OK;
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
|
|
||||||
@@ -927,14 +826,13 @@ HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout)
|
|||||||
* @brief Set the specific FLASH error flag.
|
* @brief Set the specific FLASH error flag.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void FLASH_SetErrorCode(void)
|
static void FLASH_SetErrorCode(void) {
|
||||||
{
|
|
||||||
uint32_t flags = 0U;
|
uint32_t flags = 0U;
|
||||||
|
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2))
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2))
|
||||||
#else
|
#else
|
||||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR))
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR))
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
{
|
{
|
||||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP;
|
pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP;
|
||||||
@@ -945,9 +843,9 @@ static void FLASH_SetErrorCode(void)
|
|||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
}
|
}
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2))
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2))
|
||||||
#else
|
#else
|
||||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
{
|
{
|
||||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_PROG;
|
pFlash.ErrorCode |= HAL_FLASH_ERROR_PROG;
|
||||||
@@ -957,8 +855,7 @@ static void FLASH_SetErrorCode(void)
|
|||||||
flags |= FLASH_FLAG_PGERR;
|
flags |= FLASH_FLAG_PGERR;
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
}
|
}
|
||||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR))
|
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR)) {
|
||||||
{
|
|
||||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_OPTV;
|
pFlash.ErrorCode |= HAL_FLASH_ERROR_OPTV;
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,6 @@ static uint8_t FLASH_OB_GetUser(void);
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Perform a mass erase or erase the specified FLASH memory pages
|
* @brief Perform a mass erase or erase the specified FLASH memory pages
|
||||||
* @note To correctly run this function, the @ref HAL_FLASH_Unlock() function
|
* @note To correctly run this function, the @ref HAL_FLASH_Unlock() function
|
||||||
@@ -172,8 +171,7 @@ static uint8_t FLASH_OB_GetUser(void);
|
|||||||
*
|
*
|
||||||
* @retval HAL_StatusTypeDef HAL Status
|
* @retval HAL_StatusTypeDef HAL Status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError)
|
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_ERROR;
|
HAL_StatusTypeDef status = HAL_ERROR;
|
||||||
uint32_t address = 0U;
|
uint32_t address = 0U;
|
||||||
|
|
||||||
@@ -183,23 +181,17 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
|||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase));
|
assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase));
|
||||||
|
|
||||||
if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
|
if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) {
|
||||||
{
|
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
if (pEraseInit->Banks == FLASH_BANK_BOTH)
|
if (pEraseInit->Banks == FLASH_BANK_BOTH) {
|
||||||
{
|
|
||||||
/* Mass Erase requested for Bank1 and Bank2 */
|
/* Mass Erase requested for Bank1 and Bank2 */
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && \
|
if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)) {
|
||||||
(FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK))
|
|
||||||
{
|
|
||||||
/*Mass erase to be done*/
|
/*Mass erase to be done*/
|
||||||
FLASH_MassErase(FLASH_BANK_BOTH);
|
FLASH_MassErase(FLASH_BANK_BOTH);
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && \
|
if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)) {
|
||||||
(FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK))
|
|
||||||
{
|
|
||||||
status = HAL_OK;
|
status = HAL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,13 +199,10 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
|||||||
CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
|
CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
|
||||||
CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
|
CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
|
||||||
}
|
}
|
||||||
}
|
} else if (pEraseInit->Banks == FLASH_BANK_2) {
|
||||||
else if (pEraseInit->Banks == FLASH_BANK_2)
|
|
||||||
{
|
|
||||||
/* Mass Erase requested for Bank2 */
|
/* Mass Erase requested for Bank2 */
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
|
if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) {
|
||||||
{
|
|
||||||
/*Mass erase to be done*/
|
/*Mass erase to be done*/
|
||||||
FLASH_MassErase(FLASH_BANK_2);
|
FLASH_MassErase(FLASH_BANK_2);
|
||||||
|
|
||||||
@@ -223,14 +212,12 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
|||||||
/* If the erase operation is completed, disable the MER Bit */
|
/* If the erase operation is completed, disable the MER Bit */
|
||||||
CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
|
CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
{
|
{
|
||||||
/* Mass Erase requested for Bank1 */
|
/* Mass Erase requested for Bank1 */
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
|
if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) {
|
||||||
{
|
|
||||||
/*Mass erase to be done*/
|
/*Mass erase to be done*/
|
||||||
FLASH_MassErase(FLASH_BANK_1);
|
FLASH_MassErase(FLASH_BANK_1);
|
||||||
|
|
||||||
@@ -241,9 +228,7 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
|||||||
CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
|
CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Page Erase is requested */
|
/* Page Erase is requested */
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress));
|
assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress));
|
||||||
@@ -251,19 +236,14 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
|||||||
|
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
/* Page Erase requested on address located on bank2 */
|
/* Page Erase requested on address located on bank2 */
|
||||||
if(pEraseInit->PageAddress > FLASH_BANK1_END)
|
if (pEraseInit->PageAddress > FLASH_BANK1_END) {
|
||||||
{
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
|
if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) {
|
||||||
{
|
|
||||||
/*Initialization of PageError variable*/
|
/*Initialization of PageError variable*/
|
||||||
*PageError = 0xFFFFFFFFU;
|
*PageError = 0xFFFFFFFFU;
|
||||||
|
|
||||||
/* Erase by page by page to be done*/
|
/* Erase by page by page to be done*/
|
||||||
for(address = pEraseInit->PageAddress;
|
for (address = pEraseInit->PageAddress; address < (pEraseInit->PageAddress + (pEraseInit->NbPages) * FLASH_PAGE_SIZE); address += FLASH_PAGE_SIZE) {
|
||||||
address < (pEraseInit->PageAddress + (pEraseInit->NbPages)*FLASH_PAGE_SIZE);
|
|
||||||
address += FLASH_PAGE_SIZE)
|
|
||||||
{
|
|
||||||
FLASH_PageErase(address);
|
FLASH_PageErase(address);
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
@@ -272,30 +252,24 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
|||||||
/* If the erase operation is completed, disable the PER Bit */
|
/* If the erase operation is completed, disable the PER Bit */
|
||||||
CLEAR_BIT(FLASH->CR2, FLASH_CR2_PER);
|
CLEAR_BIT(FLASH->CR2, FLASH_CR2_PER);
|
||||||
|
|
||||||
if (status != HAL_OK)
|
if (status != HAL_OK) {
|
||||||
{
|
|
||||||
/* In case of error, stop erase procedure and return the faulty address */
|
/* In case of error, stop erase procedure and return the faulty address */
|
||||||
*PageError = address;
|
*PageError = address;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
{
|
{
|
||||||
/* Page Erase requested on address located on bank1 */
|
/* Page Erase requested on address located on bank1 */
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
|
if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) {
|
||||||
{
|
|
||||||
/*Initialization of PageError variable*/
|
/*Initialization of PageError variable*/
|
||||||
*PageError = 0xFFFFFFFFU;
|
*PageError = 0xFFFFFFFFU;
|
||||||
|
|
||||||
/* Erase page by page to be done*/
|
/* Erase page by page to be done*/
|
||||||
for(address = pEraseInit->PageAddress;
|
for (address = pEraseInit->PageAddress; address < ((pEraseInit->NbPages * FLASH_PAGE_SIZE) + pEraseInit->PageAddress); address += FLASH_PAGE_SIZE) {
|
||||||
address < ((pEraseInit->NbPages * FLASH_PAGE_SIZE) + pEraseInit->PageAddress);
|
|
||||||
address += FLASH_PAGE_SIZE)
|
|
||||||
{
|
|
||||||
FLASH_PageErase(address);
|
FLASH_PageErase(address);
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
@@ -304,8 +278,7 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
|||||||
/* If the erase operation is completed, disable the PER Bit */
|
/* If the erase operation is completed, disable the PER Bit */
|
||||||
CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
|
CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
|
||||||
|
|
||||||
if (status != HAL_OK)
|
if (status != HAL_OK) {
|
||||||
{
|
|
||||||
/* In case of error, stop erase procedure and return the faulty address */
|
/* In case of error, stop erase procedure and return the faulty address */
|
||||||
*PageError = address;
|
*PageError = address;
|
||||||
break;
|
break;
|
||||||
@@ -332,16 +305,14 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
|||||||
*
|
*
|
||||||
* @retval HAL_StatusTypeDef HAL Status
|
* @retval HAL_StatusTypeDef HAL Status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
|
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
/* Process Locked */
|
/* Process Locked */
|
||||||
__HAL_LOCK(&pFlash);
|
__HAL_LOCK(&pFlash);
|
||||||
|
|
||||||
/* If procedure already ongoing, reject the next one */
|
/* If procedure already ongoing, reject the next one */
|
||||||
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
|
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,14 +327,11 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
|
|||||||
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2);
|
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
|
if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) {
|
||||||
{
|
|
||||||
/*Mass erase to be done*/
|
/*Mass erase to be done*/
|
||||||
pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE;
|
pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE;
|
||||||
FLASH_MassErase(pEraseInit->Banks);
|
FLASH_MassErase(pEraseInit->Banks);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Erase by page to be done*/
|
/* Erase by page to be done*/
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -410,8 +378,7 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
|
|||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
HAL_StatusTypeDef HAL_FLASHEx_OBErase(void)
|
HAL_StatusTypeDef HAL_FLASHEx_OBErase(void) {
|
||||||
{
|
|
||||||
uint8_t rdptmp = OB_RDP_LEVEL_0;
|
uint8_t rdptmp = OB_RDP_LEVEL_0;
|
||||||
HAL_StatusTypeDef status = HAL_ERROR;
|
HAL_StatusTypeDef status = HAL_ERROR;
|
||||||
|
|
||||||
@@ -421,8 +388,7 @@ HAL_StatusTypeDef HAL_FLASHEx_OBErase(void)
|
|||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||||
|
|
||||||
if(status == HAL_OK)
|
if (status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Clean the error context */
|
/* Clean the error context */
|
||||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||||
|
|
||||||
@@ -436,8 +402,7 @@ HAL_StatusTypeDef HAL_FLASHEx_OBErase(void)
|
|||||||
/* If the erase operation is completed, disable the OPTER Bit */
|
/* If the erase operation is completed, disable the OPTER Bit */
|
||||||
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER);
|
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER);
|
||||||
|
|
||||||
if(status == HAL_OK)
|
if (status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Restore the last read protection Option Byte value */
|
/* Restore the last read protection Option Byte value */
|
||||||
status = FLASH_OB_RDP_LevelConfig(rdptmp);
|
status = FLASH_OB_RDP_LevelConfig(rdptmp);
|
||||||
}
|
}
|
||||||
@@ -459,8 +424,7 @@ HAL_StatusTypeDef HAL_FLASHEx_OBErase(void)
|
|||||||
*
|
*
|
||||||
* @retval HAL_StatusTypeDef HAL Status
|
* @retval HAL_StatusTypeDef HAL Status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
|
HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_ERROR;
|
HAL_StatusTypeDef status = HAL_ERROR;
|
||||||
|
|
||||||
/* Process Locked */
|
/* Process Locked */
|
||||||
@@ -470,21 +434,16 @@ HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
|
|||||||
assert_param(IS_OPTIONBYTE(pOBInit->OptionType));
|
assert_param(IS_OPTIONBYTE(pOBInit->OptionType));
|
||||||
|
|
||||||
/* Write protection configuration */
|
/* Write protection configuration */
|
||||||
if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP)
|
if ((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP) {
|
||||||
{
|
|
||||||
assert_param(IS_WRPSTATE(pOBInit->WRPState));
|
assert_param(IS_WRPSTATE(pOBInit->WRPState));
|
||||||
if (pOBInit->WRPState == OB_WRPSTATE_ENABLE)
|
if (pOBInit->WRPState == OB_WRPSTATE_ENABLE) {
|
||||||
{
|
|
||||||
/* Enable of Write protection on the selected page */
|
/* Enable of Write protection on the selected page */
|
||||||
status = FLASH_OB_EnableWRP(pOBInit->WRPPage);
|
status = FLASH_OB_EnableWRP(pOBInit->WRPPage);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Disable of Write protection on the selected page */
|
/* Disable of Write protection on the selected page */
|
||||||
status = FLASH_OB_DisableWRP(pOBInit->WRPPage);
|
status = FLASH_OB_DisableWRP(pOBInit->WRPPage);
|
||||||
}
|
}
|
||||||
if (status != HAL_OK)
|
if (status != HAL_OK) {
|
||||||
{
|
|
||||||
/* Process Unlocked */
|
/* Process Unlocked */
|
||||||
__HAL_UNLOCK(&pFlash);
|
__HAL_UNLOCK(&pFlash);
|
||||||
return status;
|
return status;
|
||||||
@@ -492,11 +451,9 @@ HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read protection configuration */
|
/* Read protection configuration */
|
||||||
if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP)
|
if ((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP) {
|
||||||
{
|
|
||||||
status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel);
|
status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel);
|
||||||
if (status != HAL_OK)
|
if (status != HAL_OK) {
|
||||||
{
|
|
||||||
/* Process Unlocked */
|
/* Process Unlocked */
|
||||||
__HAL_UNLOCK(&pFlash);
|
__HAL_UNLOCK(&pFlash);
|
||||||
return status;
|
return status;
|
||||||
@@ -504,11 +461,9 @@ HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* USER configuration */
|
/* USER configuration */
|
||||||
if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER)
|
if ((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER) {
|
||||||
{
|
|
||||||
status = FLASH_OB_UserConfig(pOBInit->USERConfig);
|
status = FLASH_OB_UserConfig(pOBInit->USERConfig);
|
||||||
if (status != HAL_OK)
|
if (status != HAL_OK) {
|
||||||
{
|
|
||||||
/* Process Unlocked */
|
/* Process Unlocked */
|
||||||
__HAL_UNLOCK(&pFlash);
|
__HAL_UNLOCK(&pFlash);
|
||||||
return status;
|
return status;
|
||||||
@@ -516,11 +471,9 @@ HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* DATA configuration*/
|
/* DATA configuration*/
|
||||||
if((pOBInit->OptionType & OPTIONBYTE_DATA) == OPTIONBYTE_DATA)
|
if ((pOBInit->OptionType & OPTIONBYTE_DATA) == OPTIONBYTE_DATA) {
|
||||||
{
|
|
||||||
status = FLASH_OB_ProgramData(pOBInit->DATAAddress, pOBInit->DATAData);
|
status = FLASH_OB_ProgramData(pOBInit->DATAAddress, pOBInit->DATAData);
|
||||||
if (status != HAL_OK)
|
if (status != HAL_OK) {
|
||||||
{
|
|
||||||
/* Process Unlocked */
|
/* Process Unlocked */
|
||||||
__HAL_UNLOCK(&pFlash);
|
__HAL_UNLOCK(&pFlash);
|
||||||
return status;
|
return status;
|
||||||
@@ -540,8 +493,7 @@ HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
|
|||||||
*
|
*
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
|
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) {
|
||||||
{
|
|
||||||
pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER;
|
pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER;
|
||||||
|
|
||||||
/*Get WRP*/
|
/*Get WRP*/
|
||||||
@@ -562,17 +514,13 @@ void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
|
|||||||
* @arg @ref OB_DATA_ADDRESS_DATA1
|
* @arg @ref OB_DATA_ADDRESS_DATA1
|
||||||
* @retval Value programmed in USER data
|
* @retval Value programmed in USER data
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress)
|
uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress) {
|
||||||
{
|
|
||||||
uint32_t value = 0;
|
uint32_t value = 0;
|
||||||
|
|
||||||
if (DATAAdress == OB_DATA_ADDRESS_DATA0)
|
if (DATAAdress == OB_DATA_ADDRESS_DATA0) {
|
||||||
{
|
|
||||||
/* Get value programmed in OB USER Data0 */
|
/* Get value programmed in OB USER Data0 */
|
||||||
value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA0) >> FLASH_POSITION_OB_USERDATA0_BIT;
|
value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA0) >> FLASH_POSITION_OB_USERDATA0_BIT;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Get value programmed in OB USER Data1 */
|
/* Get value programmed in OB USER Data1 */
|
||||||
value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA1) >> FLASH_POSITION_OB_USERDATA1_BIT;
|
value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA1) >> FLASH_POSITION_OB_USERDATA1_BIT;
|
||||||
}
|
}
|
||||||
@@ -608,8 +556,7 @@ uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress)
|
|||||||
*
|
*
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void FLASH_MassErase(uint32_t Banks)
|
static void FLASH_MassErase(uint32_t Banks) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_FLASH_BANK(Banks));
|
assert_param(IS_FLASH_BANK(Banks));
|
||||||
|
|
||||||
@@ -617,22 +564,17 @@ static void FLASH_MassErase(uint32_t Banks)
|
|||||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||||
|
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
if(Banks == FLASH_BANK_BOTH)
|
if (Banks == FLASH_BANK_BOTH) {
|
||||||
{
|
|
||||||
/* bank1 & bank2 will be erased*/
|
/* bank1 & bank2 will be erased*/
|
||||||
SET_BIT(FLASH->CR, FLASH_CR_MER);
|
SET_BIT(FLASH->CR, FLASH_CR_MER);
|
||||||
SET_BIT(FLASH->CR2, FLASH_CR2_MER);
|
SET_BIT(FLASH->CR2, FLASH_CR2_MER);
|
||||||
SET_BIT(FLASH->CR, FLASH_CR_STRT);
|
SET_BIT(FLASH->CR, FLASH_CR_STRT);
|
||||||
SET_BIT(FLASH->CR2, FLASH_CR2_STRT);
|
SET_BIT(FLASH->CR2, FLASH_CR2_STRT);
|
||||||
}
|
} else if (Banks == FLASH_BANK_2) {
|
||||||
else if(Banks == FLASH_BANK_2)
|
|
||||||
{
|
|
||||||
/*Only bank2 will be erased*/
|
/*Only bank2 will be erased*/
|
||||||
SET_BIT(FLASH->CR2, FLASH_CR2_MER);
|
SET_BIT(FLASH->CR2, FLASH_CR2_MER);
|
||||||
SET_BIT(FLASH->CR2, FLASH_CR2_STRT);
|
SET_BIT(FLASH->CR2, FLASH_CR2_STRT);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
#if !defined(FLASH_BANK2_END)
|
#if !defined(FLASH_BANK2_END)
|
||||||
/* Prevent unused argument(s) compilation warning */
|
/* Prevent unused argument(s) compilation warning */
|
||||||
@@ -657,8 +599,7 @@ static void FLASH_MassErase(uint32_t Banks)
|
|||||||
* The value of this parameter depend on device used within the same series
|
* The value of this parameter depend on device used within the same series
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
|
static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
uint16_t WRP0_Data = 0xFFFF;
|
uint16_t WRP0_Data = 0xFFFF;
|
||||||
#if defined(FLASH_WRP1_WRP1)
|
#if defined(FLASH_WRP1_WRP1)
|
||||||
@@ -709,21 +650,18 @@ static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
|
|||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||||
|
|
||||||
if(status == HAL_OK)
|
if (status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Clean the error context */
|
/* Clean the error context */
|
||||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||||
|
|
||||||
/* To be able to write again option byte, need to perform a option byte erase */
|
/* To be able to write again option byte, need to perform a option byte erase */
|
||||||
status = HAL_FLASHEx_OBErase();
|
status = HAL_FLASHEx_OBErase();
|
||||||
if (status == HAL_OK)
|
if (status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Enable write protection */
|
/* Enable write protection */
|
||||||
SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
|
SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
|
||||||
|
|
||||||
#if defined(FLASH_WRP0_WRP0)
|
#if defined(FLASH_WRP0_WRP0)
|
||||||
if(WRP0_Data != 0xFFU)
|
if (WRP0_Data != 0xFFU) {
|
||||||
{
|
|
||||||
OB->WRP0 &= WRP0_Data;
|
OB->WRP0 &= WRP0_Data;
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
@@ -732,8 +670,7 @@ static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
|
|||||||
#endif /* FLASH_WRP0_WRP0 */
|
#endif /* FLASH_WRP0_WRP0 */
|
||||||
|
|
||||||
#if defined(FLASH_WRP1_WRP1)
|
#if defined(FLASH_WRP1_WRP1)
|
||||||
if((status == HAL_OK) && (WRP1_Data != 0xFFU))
|
if ((status == HAL_OK) && (WRP1_Data != 0xFFU)) {
|
||||||
{
|
|
||||||
OB->WRP1 &= WRP1_Data;
|
OB->WRP1 &= WRP1_Data;
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
@@ -742,8 +679,7 @@ static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
|
|||||||
#endif /* FLASH_WRP1_WRP1 */
|
#endif /* FLASH_WRP1_WRP1 */
|
||||||
|
|
||||||
#if defined(FLASH_WRP2_WRP2)
|
#if defined(FLASH_WRP2_WRP2)
|
||||||
if((status == HAL_OK) && (WRP2_Data != 0xFFU))
|
if ((status == HAL_OK) && (WRP2_Data != 0xFFU)) {
|
||||||
{
|
|
||||||
OB->WRP2 &= WRP2_Data;
|
OB->WRP2 &= WRP2_Data;
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
@@ -752,8 +688,7 @@ static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
|
|||||||
#endif /* FLASH_WRP2_WRP2 */
|
#endif /* FLASH_WRP2_WRP2 */
|
||||||
|
|
||||||
#if defined(FLASH_WRP3_WRP3)
|
#if defined(FLASH_WRP3_WRP3)
|
||||||
if((status == HAL_OK) && (WRP3_Data != 0xFFU))
|
if ((status == HAL_OK) && (WRP3_Data != 0xFFU)) {
|
||||||
{
|
|
||||||
OB->WRP3 &= WRP3_Data;
|
OB->WRP3 &= WRP3_Data;
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
@@ -780,8 +715,7 @@ static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
|
|||||||
* The value of this parameter depend on device used within the same series
|
* The value of this parameter depend on device used within the same series
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
|
static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
uint16_t WRP0_Data = 0xFFFF;
|
uint16_t WRP0_Data = 0xFFFF;
|
||||||
#if defined(FLASH_WRP1_WRP1)
|
#if defined(FLASH_WRP1_WRP1)
|
||||||
@@ -829,24 +763,20 @@ static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
|
|||||||
WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24U);
|
WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24U);
|
||||||
#endif /* OB_WRP_PAGES96TO127MASK */
|
#endif /* OB_WRP_PAGES96TO127MASK */
|
||||||
|
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||||
|
|
||||||
if(status == HAL_OK)
|
if (status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Clean the error context */
|
/* Clean the error context */
|
||||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||||
|
|
||||||
/* To be able to write again option byte, need to perform a option byte erase */
|
/* To be able to write again option byte, need to perform a option byte erase */
|
||||||
status = HAL_FLASHEx_OBErase();
|
status = HAL_FLASHEx_OBErase();
|
||||||
if (status == HAL_OK)
|
if (status == HAL_OK) {
|
||||||
{
|
|
||||||
SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
|
SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
|
||||||
|
|
||||||
#if defined(FLASH_WRP0_WRP0)
|
#if defined(FLASH_WRP0_WRP0)
|
||||||
if(WRP0_Data != 0xFFU)
|
if (WRP0_Data != 0xFFU) {
|
||||||
{
|
|
||||||
OB->WRP0 |= WRP0_Data;
|
OB->WRP0 |= WRP0_Data;
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
@@ -855,8 +785,7 @@ static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
|
|||||||
#endif /* FLASH_WRP0_WRP0 */
|
#endif /* FLASH_WRP0_WRP0 */
|
||||||
|
|
||||||
#if defined(FLASH_WRP1_WRP1)
|
#if defined(FLASH_WRP1_WRP1)
|
||||||
if((status == HAL_OK) && (WRP1_Data != 0xFFU))
|
if ((status == HAL_OK) && (WRP1_Data != 0xFFU)) {
|
||||||
{
|
|
||||||
OB->WRP1 |= WRP1_Data;
|
OB->WRP1 |= WRP1_Data;
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
@@ -865,8 +794,7 @@ static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
|
|||||||
#endif /* FLASH_WRP1_WRP1 */
|
#endif /* FLASH_WRP1_WRP1 */
|
||||||
|
|
||||||
#if defined(FLASH_WRP2_WRP2)
|
#if defined(FLASH_WRP2_WRP2)
|
||||||
if((status == HAL_OK) && (WRP2_Data != 0xFFU))
|
if ((status == HAL_OK) && (WRP2_Data != 0xFFU)) {
|
||||||
{
|
|
||||||
OB->WRP2 |= WRP2_Data;
|
OB->WRP2 |= WRP2_Data;
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
@@ -875,8 +803,7 @@ static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
|
|||||||
#endif /* FLASH_WRP2_WRP2 */
|
#endif /* FLASH_WRP2_WRP2 */
|
||||||
|
|
||||||
#if defined(FLASH_WRP3_WRP3)
|
#if defined(FLASH_WRP3_WRP3)
|
||||||
if((status == HAL_OK) && (WRP3_Data != 0xFFU))
|
if ((status == HAL_OK) && (WRP3_Data != 0xFFU)) {
|
||||||
{
|
|
||||||
OB->WRP3 |= WRP3_Data;
|
OB->WRP3 |= WRP3_Data;
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
@@ -899,8 +826,7 @@ static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
|
|||||||
* @arg @ref OB_RDP_LEVEL_1 Read protection of the memory
|
* @arg @ref OB_RDP_LEVEL_1 Read protection of the memory
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel)
|
static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -909,8 +835,7 @@ static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel)
|
|||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||||
|
|
||||||
if(status == HAL_OK)
|
if (status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Clean the error context */
|
/* Clean the error context */
|
||||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||||
|
|
||||||
@@ -924,8 +849,7 @@ static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel)
|
|||||||
/* If the erase operation is completed, disable the OPTER Bit */
|
/* If the erase operation is completed, disable the OPTER Bit */
|
||||||
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER);
|
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER);
|
||||||
|
|
||||||
if(status == HAL_OK)
|
if (status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Enable the Option Bytes Programming operation */
|
/* Enable the Option Bytes Programming operation */
|
||||||
SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
|
SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
|
||||||
|
|
||||||
@@ -950,23 +874,21 @@ static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel)
|
|||||||
* And BFBF2(Bit5) for STM32F101xG and STM32F103xG .
|
* And BFBF2(Bit5) for STM32F101xG and STM32F103xG .
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig)
|
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_OB_IWDG_SOURCE((UserConfig&OB_IWDG_SW)));
|
assert_param(IS_OB_IWDG_SOURCE((UserConfig & OB_IWDG_SW)));
|
||||||
assert_param(IS_OB_STOP_SOURCE((UserConfig&OB_STOP_NO_RST)));
|
assert_param(IS_OB_STOP_SOURCE((UserConfig & OB_STOP_NO_RST)));
|
||||||
assert_param(IS_OB_STDBY_SOURCE((UserConfig&OB_STDBY_NO_RST)));
|
assert_param(IS_OB_STDBY_SOURCE((UserConfig & OB_STDBY_NO_RST)));
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
assert_param(IS_OB_BOOT1((UserConfig&OB_BOOT1_SET)));
|
assert_param(IS_OB_BOOT1((UserConfig & OB_BOOT1_SET)));
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||||
|
|
||||||
if(status == HAL_OK)
|
if (status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Clean the error context */
|
/* Clean the error context */
|
||||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||||
|
|
||||||
@@ -1001,8 +923,7 @@ static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig)
|
|||||||
* @param Data specifies the data to be programmed.
|
* @param Data specifies the data to be programmed.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data)
|
static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data) {
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_ERROR;
|
HAL_StatusTypeDef status = HAL_ERROR;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -1011,14 +932,13 @@ static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data)
|
|||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||||
|
|
||||||
if(status == HAL_OK)
|
if (status == HAL_OK) {
|
||||||
{
|
|
||||||
/* Clean the error context */
|
/* Clean the error context */
|
||||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||||
|
|
||||||
/* Enables the Option Bytes Programming operation */
|
/* Enables the Option Bytes Programming operation */
|
||||||
SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
|
SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
|
||||||
*(__IO uint16_t*)Address = Data;
|
*(__IO uint16_t *)Address = Data;
|
||||||
|
|
||||||
/* Wait for last operation to be completed */
|
/* Wait for last operation to be completed */
|
||||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||||
@@ -1034,8 +954,7 @@ static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data)
|
|||||||
* @brief Return the FLASH Write Protection Option Bytes value.
|
* @brief Return the FLASH Write Protection Option Bytes value.
|
||||||
* @retval The FLASH Write Protection Option Bytes value
|
* @retval The FLASH Write Protection Option Bytes value
|
||||||
*/
|
*/
|
||||||
static uint32_t FLASH_OB_GetWRP(void)
|
static uint32_t FLASH_OB_GetWRP(void) {
|
||||||
{
|
|
||||||
/* Return the FLASH write protection Register value */
|
/* Return the FLASH write protection Register value */
|
||||||
return (uint32_t)(READ_REG(FLASH->WRPR));
|
return (uint32_t)(READ_REG(FLASH->WRPR));
|
||||||
}
|
}
|
||||||
@@ -1047,20 +966,16 @@ static uint32_t FLASH_OB_GetWRP(void)
|
|||||||
* @arg @ref OB_RDP_LEVEL_0 No protection
|
* @arg @ref OB_RDP_LEVEL_0 No protection
|
||||||
* @arg @ref OB_RDP_LEVEL_1 Read protection of the memory
|
* @arg @ref OB_RDP_LEVEL_1 Read protection of the memory
|
||||||
*/
|
*/
|
||||||
static uint32_t FLASH_OB_GetRDP(void)
|
static uint32_t FLASH_OB_GetRDP(void) {
|
||||||
{
|
|
||||||
uint32_t readstatus = OB_RDP_LEVEL_0;
|
uint32_t readstatus = OB_RDP_LEVEL_0;
|
||||||
uint32_t tmp_reg = 0U;
|
uint32_t tmp_reg = 0U;
|
||||||
|
|
||||||
/* Read RDP level bits */
|
/* Read RDP level bits */
|
||||||
tmp_reg = READ_BIT(FLASH->OBR, FLASH_OBR_RDPRT);
|
tmp_reg = READ_BIT(FLASH->OBR, FLASH_OBR_RDPRT);
|
||||||
|
|
||||||
if (tmp_reg == FLASH_OBR_RDPRT)
|
if (tmp_reg == FLASH_OBR_RDPRT) {
|
||||||
{
|
|
||||||
readstatus = OB_RDP_LEVEL_1;
|
readstatus = OB_RDP_LEVEL_1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
readstatus = OB_RDP_LEVEL_0;
|
readstatus = OB_RDP_LEVEL_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1073,8 +988,7 @@ static uint32_t FLASH_OB_GetRDP(void)
|
|||||||
* FLASH_OBR_nRST_STOP(Bit3),FLASH_OBR_nRST_STDBY(Bit4).
|
* FLASH_OBR_nRST_STOP(Bit3),FLASH_OBR_nRST_STDBY(Bit4).
|
||||||
* And FLASH_OBR_BFB2(Bit5) for STM32F101xG and STM32F103xG .
|
* And FLASH_OBR_BFB2(Bit5) for STM32F101xG and STM32F103xG .
|
||||||
*/
|
*/
|
||||||
static uint8_t FLASH_OB_GetUser(void)
|
static uint8_t FLASH_OB_GetUser(void) {
|
||||||
{
|
|
||||||
/* Return the User Option Byte */
|
/* Return the User Option Byte */
|
||||||
return (uint8_t)((READ_REG(FLASH->OBR) & FLASH_OBR_USER) >> FLASH_POSITION_IWDGSW_BIT);
|
return (uint8_t)((READ_REG(FLASH->OBR) & FLASH_OBR_USER) >> FLASH_POSITION_IWDGSW_BIT);
|
||||||
}
|
}
|
||||||
@@ -1102,21 +1016,17 @@ static uint8_t FLASH_OB_GetUser(void)
|
|||||||
*
|
*
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void FLASH_PageErase(uint32_t PageAddress)
|
void FLASH_PageErase(uint32_t PageAddress) {
|
||||||
{
|
|
||||||
/* Clean the error context */
|
/* Clean the error context */
|
||||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||||
|
|
||||||
#if defined(FLASH_BANK2_END)
|
#if defined(FLASH_BANK2_END)
|
||||||
if(PageAddress > FLASH_BANK1_END)
|
if (PageAddress > FLASH_BANK1_END) {
|
||||||
{
|
|
||||||
/* Proceed to erase the page */
|
/* Proceed to erase the page */
|
||||||
SET_BIT(FLASH->CR2, FLASH_CR2_PER);
|
SET_BIT(FLASH->CR2, FLASH_CR2_PER);
|
||||||
WRITE_REG(FLASH->AR2, PageAddress);
|
WRITE_REG(FLASH->AR2, PageAddress);
|
||||||
SET_BIT(FLASH->CR2, FLASH_CR2_STRT);
|
SET_BIT(FLASH->CR2, FLASH_CR2_STRT);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
#endif /* FLASH_BANK2_END */
|
#endif /* FLASH_BANK2_END */
|
||||||
/* Proceed to erase the page */
|
/* Proceed to erase the page */
|
||||||
SET_BIT(FLASH->CR, FLASH_CR_PER);
|
SET_BIT(FLASH->CR, FLASH_CR_PER);
|
||||||
|
|||||||
@@ -183,7 +183,6 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes the GPIOx peripheral according to the specified parameters in the GPIO_Init.
|
* @brief Initializes the GPIOx peripheral according to the specified parameters in the GPIO_Init.
|
||||||
* @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral
|
* @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral
|
||||||
@@ -191,8 +190,7 @@
|
|||||||
* the configuration information for the specified GPIO peripheral.
|
* the configuration information for the specified GPIO peripheral.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init) {
|
||||||
{
|
|
||||||
uint32_t position;
|
uint32_t position;
|
||||||
uint32_t ioposition = 0x00U;
|
uint32_t ioposition = 0x00U;
|
||||||
uint32_t iocurrent = 0x00U;
|
uint32_t iocurrent = 0x00U;
|
||||||
@@ -207,22 +205,19 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
|||||||
assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
|
assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
|
||||||
|
|
||||||
/* Configure the port pins */
|
/* Configure the port pins */
|
||||||
for (position = 0U; position < GPIO_NUMBER; position++)
|
for (position = 0U; position < GPIO_NUMBER; position++) {
|
||||||
{
|
|
||||||
/* Get the IO position */
|
/* Get the IO position */
|
||||||
ioposition = (0x01U << position);
|
ioposition = (0x01U << position);
|
||||||
|
|
||||||
/* Get the current IO position */
|
/* Get the current IO position */
|
||||||
iocurrent = (uint32_t)(GPIO_Init->Pin) & ioposition;
|
iocurrent = (uint32_t)(GPIO_Init->Pin) & ioposition;
|
||||||
|
|
||||||
if (iocurrent == ioposition)
|
if (iocurrent == ioposition) {
|
||||||
{
|
|
||||||
/* Check the Alternate function parameters */
|
/* Check the Alternate function parameters */
|
||||||
assert_param(IS_GPIO_AF_INSTANCE(GPIOx));
|
assert_param(IS_GPIO_AF_INSTANCE(GPIOx));
|
||||||
|
|
||||||
/* Based on the required mode, filling config variable with MODEy[1:0] and CNFy[3:2] corresponding bits */
|
/* Based on the required mode, filling config variable with MODEy[1:0] and CNFy[3:2] corresponding bits */
|
||||||
switch (GPIO_Init->Mode)
|
switch (GPIO_Init->Mode) {
|
||||||
{
|
|
||||||
/* If we are configuring the pin in OUTPUT push-pull mode */
|
/* If we are configuring the pin in OUTPUT push-pull mode */
|
||||||
case GPIO_MODE_OUTPUT_PP:
|
case GPIO_MODE_OUTPUT_PP:
|
||||||
/* Check the GPIO speed parameter */
|
/* Check the GPIO speed parameter */
|
||||||
@@ -261,18 +256,14 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
|||||||
case GPIO_MODE_EVT_RISING_FALLING:
|
case GPIO_MODE_EVT_RISING_FALLING:
|
||||||
/* Check the GPIO pull parameter */
|
/* Check the GPIO pull parameter */
|
||||||
assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
|
assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
|
||||||
if (GPIO_Init->Pull == GPIO_NOPULL)
|
if (GPIO_Init->Pull == GPIO_NOPULL) {
|
||||||
{
|
|
||||||
config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_FLOATING;
|
config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_FLOATING;
|
||||||
}
|
} else if (GPIO_Init->Pull == GPIO_PULLUP) {
|
||||||
else if (GPIO_Init->Pull == GPIO_PULLUP)
|
|
||||||
{
|
|
||||||
config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_PU_PD;
|
config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_PU_PD;
|
||||||
|
|
||||||
/* Set the corresponding ODR bit */
|
/* Set the corresponding ODR bit */
|
||||||
GPIOx->BSRR = ioposition;
|
GPIOx->BSRR = ioposition;
|
||||||
}
|
} else /* GPIO_PULLDOWN */
|
||||||
else /* GPIO_PULLDOWN */
|
|
||||||
{
|
{
|
||||||
config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_PU_PD;
|
config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_PU_PD;
|
||||||
|
|
||||||
@@ -301,8 +292,7 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
|||||||
|
|
||||||
/*--------------------- EXTI Mode Configuration ------------------------*/
|
/*--------------------- EXTI Mode Configuration ------------------------*/
|
||||||
/* Configure the External Interrupt or event for the current IO */
|
/* Configure the External Interrupt or event for the current IO */
|
||||||
if ((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE)
|
if ((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE) {
|
||||||
{
|
|
||||||
/* Enable AFIO Clock */
|
/* Enable AFIO Clock */
|
||||||
__HAL_RCC_AFIO_CLK_ENABLE();
|
__HAL_RCC_AFIO_CLK_ENABLE();
|
||||||
temp = AFIO->EXTICR[position >> 2U];
|
temp = AFIO->EXTICR[position >> 2U];
|
||||||
@@ -310,44 +300,31 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
|||||||
SET_BIT(temp, (GPIO_GET_INDEX(GPIOx)) << (4U * (position & 0x03U)));
|
SET_BIT(temp, (GPIO_GET_INDEX(GPIOx)) << (4U * (position & 0x03U)));
|
||||||
AFIO->EXTICR[position >> 2U] = temp;
|
AFIO->EXTICR[position >> 2U] = temp;
|
||||||
|
|
||||||
|
|
||||||
/* Configure the interrupt mask */
|
/* Configure the interrupt mask */
|
||||||
if ((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
|
if ((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT) {
|
||||||
{
|
|
||||||
SET_BIT(EXTI->IMR, iocurrent);
|
SET_BIT(EXTI->IMR, iocurrent);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
CLEAR_BIT(EXTI->IMR, iocurrent);
|
CLEAR_BIT(EXTI->IMR, iocurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Configure the event mask */
|
/* Configure the event mask */
|
||||||
if ((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT)
|
if ((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT) {
|
||||||
{
|
|
||||||
SET_BIT(EXTI->EMR, iocurrent);
|
SET_BIT(EXTI->EMR, iocurrent);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
CLEAR_BIT(EXTI->EMR, iocurrent);
|
CLEAR_BIT(EXTI->EMR, iocurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enable or disable the rising trigger */
|
/* Enable or disable the rising trigger */
|
||||||
if ((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE)
|
if ((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE) {
|
||||||
{
|
|
||||||
SET_BIT(EXTI->RTSR, iocurrent);
|
SET_BIT(EXTI->RTSR, iocurrent);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
CLEAR_BIT(EXTI->RTSR, iocurrent);
|
CLEAR_BIT(EXTI->RTSR, iocurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enable or disable the falling trigger */
|
/* Enable or disable the falling trigger */
|
||||||
if ((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE)
|
if ((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE) {
|
||||||
{
|
|
||||||
SET_BIT(EXTI->FTSR, iocurrent);
|
SET_BIT(EXTI->FTSR, iocurrent);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
CLEAR_BIT(EXTI->FTSR, iocurrent);
|
CLEAR_BIT(EXTI->FTSR, iocurrent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -362,8 +339,7 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
|||||||
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
|
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
|
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) {
|
||||||
{
|
|
||||||
uint32_t position = 0x00U;
|
uint32_t position = 0x00U;
|
||||||
uint32_t iocurrent = 0x00U;
|
uint32_t iocurrent = 0x00U;
|
||||||
uint32_t tmp = 0x00U;
|
uint32_t tmp = 0x00U;
|
||||||
@@ -375,13 +351,11 @@ void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
|
|||||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||||
|
|
||||||
/* Configure the port pins */
|
/* Configure the port pins */
|
||||||
while ((GPIO_Pin >> position) != 0U)
|
while ((GPIO_Pin >> position) != 0U) {
|
||||||
{
|
|
||||||
/* Get current io position */
|
/* Get current io position */
|
||||||
iocurrent = (GPIO_Pin) & (1U << position);
|
iocurrent = (GPIO_Pin) & (1U << position);
|
||||||
|
|
||||||
if (iocurrent)
|
if (iocurrent) {
|
||||||
{
|
|
||||||
/*------------------------- GPIO Mode Configuration --------------------*/
|
/*------------------------- GPIO Mode Configuration --------------------*/
|
||||||
/* Check if the current bit belongs to first half or last half of the pin count number
|
/* Check if the current bit belongs to first half or last half of the pin count number
|
||||||
in order to address CRH or CRL register */
|
in order to address CRH or CRL register */
|
||||||
@@ -399,8 +373,7 @@ void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
|
|||||||
|
|
||||||
tmp = AFIO->EXTICR[position >> 2U];
|
tmp = AFIO->EXTICR[position >> 2U];
|
||||||
tmp &= 0x0FU << (4U * (position & 0x03U));
|
tmp &= 0x0FU << (4U * (position & 0x03U));
|
||||||
if (tmp == (GPIO_GET_INDEX(GPIOx) << (4U * (position & 0x03U))))
|
if (tmp == (GPIO_GET_INDEX(GPIOx) << (4U * (position & 0x03U)))) {
|
||||||
{
|
|
||||||
tmp = 0x0FU << (4U * (position & 0x03U));
|
tmp = 0x0FU << (4U * (position & 0x03U));
|
||||||
CLEAR_BIT(AFIO->EXTICR[position >> 2U], tmp);
|
CLEAR_BIT(AFIO->EXTICR[position >> 2U], tmp);
|
||||||
|
|
||||||
@@ -443,19 +416,15 @@ void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
|
|||||||
* This parameter can be GPIO_PIN_x where x can be (0..15).
|
* This parameter can be GPIO_PIN_x where x can be (0..15).
|
||||||
* @retval The input port pin value.
|
* @retval The input port pin value.
|
||||||
*/
|
*/
|
||||||
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) {
|
||||||
{
|
|
||||||
GPIO_PinState bitstatus;
|
GPIO_PinState bitstatus;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||||
|
|
||||||
if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET)
|
if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET) {
|
||||||
{
|
|
||||||
bitstatus = GPIO_PIN_SET;
|
bitstatus = GPIO_PIN_SET;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
bitstatus = GPIO_PIN_RESET;
|
bitstatus = GPIO_PIN_RESET;
|
||||||
}
|
}
|
||||||
return bitstatus;
|
return bitstatus;
|
||||||
@@ -477,18 +446,14 @@ GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
|||||||
* @arg GPIO_PIN_SET: to set the port pin
|
* @arg GPIO_PIN_SET: to set the port pin
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
|
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||||
assert_param(IS_GPIO_PIN_ACTION(PinState));
|
assert_param(IS_GPIO_PIN_ACTION(PinState));
|
||||||
|
|
||||||
if (PinState != GPIO_PIN_RESET)
|
if (PinState != GPIO_PIN_RESET) {
|
||||||
{
|
|
||||||
GPIOx->BSRR = GPIO_Pin;
|
GPIOx->BSRR = GPIO_Pin;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
GPIOx->BSRR = (uint32_t)GPIO_Pin << 16U;
|
GPIOx->BSRR = (uint32_t)GPIO_Pin << 16U;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -499,8 +464,7 @@ void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState Pin
|
|||||||
* @param GPIO_Pin: Specifies the pins to be toggled.
|
* @param GPIO_Pin: Specifies the pins to be toggled.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||||
|
|
||||||
@@ -508,17 +472,16 @@ void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Locks GPIO Pins configuration registers.
|
* @brief Locks GPIO Pins configuration registers.
|
||||||
* @note The locking mechanism allows the IO configuration to be frozen. When the LOCK sequence
|
* @note The locking mechanism allows the IO configuration to be frozen. When the LOCK sequence
|
||||||
* has been applied on a port bit, it is no longer possible to modify the value of the port bit until
|
* has been applied on a port bit, it is no longer possible to modify the value of the port bit until
|
||||||
* the next reset.
|
* the next reset.
|
||||||
* @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral
|
* @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral
|
||||||
* @param GPIO_Pin: specifies the port bit to be locked.
|
* @param GPIO_Pin: specifies the port bit to be locked.
|
||||||
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) {
|
||||||
{
|
|
||||||
__IO uint32_t tmp = GPIO_LCKR_LCKK;
|
__IO uint32_t tmp = GPIO_LCKR_LCKK;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -536,12 +499,9 @@ HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
|||||||
/* Read LCKK bit*/
|
/* Read LCKK bit*/
|
||||||
tmp = GPIOx->LCKR;
|
tmp = GPIOx->LCKR;
|
||||||
|
|
||||||
if ((uint32_t)(GPIOx->LCKR & GPIO_LCKR_LCKK))
|
if ((uint32_t)(GPIOx->LCKR & GPIO_LCKR_LCKK)) {
|
||||||
{
|
|
||||||
return HAL_OK;
|
return HAL_OK;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -551,11 +511,9 @@ HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
|||||||
* @param GPIO_Pin: Specifies the pins connected EXTI line
|
* @param GPIO_Pin: Specifies the pins connected EXTI line
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
|
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin) {
|
||||||
{
|
|
||||||
/* EXTI line interrupt detected */
|
/* EXTI line interrupt detected */
|
||||||
if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
|
if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET) {
|
||||||
{
|
|
||||||
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
|
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
|
||||||
HAL_GPIO_EXTI_Callback(GPIO_Pin);
|
HAL_GPIO_EXTI_Callback(GPIO_Pin);
|
||||||
}
|
}
|
||||||
@@ -566,8 +524,7 @@ void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
|
|||||||
* @param GPIO_Pin: Specifies the pins connected EXTI line
|
* @param GPIO_Pin: Specifies the pins connected EXTI line
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
|
||||||
{
|
|
||||||
/* Prevent unused argument(s) compilation warning */
|
/* Prevent unused argument(s) compilation warning */
|
||||||
UNUSED(GPIO_Pin);
|
UNUSED(GPIO_Pin);
|
||||||
/* NOTE: This function Should not be modified, when the callback is needed,
|
/* NOTE: This function Should not be modified, when the callback is needed,
|
||||||
|
|||||||
@@ -94,8 +94,7 @@
|
|||||||
* This parameter can be a value of @ref GPIOEx_EVENTOUT_PIN.
|
* This parameter can be a value of @ref GPIOEx_EVENTOUT_PIN.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_GPIOEx_ConfigEventout(uint32_t GPIO_PortSource, uint32_t GPIO_PinSource)
|
void HAL_GPIOEx_ConfigEventout(uint32_t GPIO_PortSource, uint32_t GPIO_PinSource) {
|
||||||
{
|
|
||||||
/* Verify the parameters */
|
/* Verify the parameters */
|
||||||
assert_param(IS_AFIO_EVENTOUT_PORT(GPIO_PortSource));
|
assert_param(IS_AFIO_EVENTOUT_PORT(GPIO_PortSource));
|
||||||
assert_param(IS_AFIO_EVENTOUT_PIN(GPIO_PinSource));
|
assert_param(IS_AFIO_EVENTOUT_PIN(GPIO_PinSource));
|
||||||
@@ -108,19 +107,13 @@ void HAL_GPIOEx_ConfigEventout(uint32_t GPIO_PortSource, uint32_t GPIO_PinSource
|
|||||||
* @brief Enables the Event Output.
|
* @brief Enables the Event Output.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_GPIOEx_EnableEventout(void)
|
void HAL_GPIOEx_EnableEventout(void) { SET_BIT(AFIO->EVCR, AFIO_EVCR_EVOE); }
|
||||||
{
|
|
||||||
SET_BIT(AFIO->EVCR, AFIO_EVCR_EVOE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Disables the Event Output.
|
* @brief Disables the Event Output.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_GPIOEx_DisableEventout(void)
|
void HAL_GPIOEx_DisableEventout(void) { CLEAR_BIT(AFIO->EVCR, AFIO_EVCR_EVOE); }
|
||||||
{
|
|
||||||
CLEAR_BIT(AFIO->EVCR, AFIO_EVCR_EVOE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -159,13 +159,11 @@
|
|||||||
* the configuration information for the specified IWDG module.
|
* the configuration information for the specified IWDG module.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
|
HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg) {
|
||||||
{
|
|
||||||
uint32_t tickstart;
|
uint32_t tickstart;
|
||||||
|
|
||||||
/* Check the IWDG handle allocation */
|
/* Check the IWDG handle allocation */
|
||||||
if (hiwdg == NULL)
|
if (hiwdg == NULL) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,10 +186,8 @@ HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait for register to be updated */
|
/* Wait for register to be updated */
|
||||||
while (hiwdg->Instance->SR != RESET)
|
while (hiwdg->Instance->SR != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT) {
|
||||||
if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,8 +223,7 @@ HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
|
|||||||
* the configuration information for the specified IWDG module.
|
* the configuration information for the specified IWDG module.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg)
|
HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg) {
|
||||||
{
|
|
||||||
/* Reload IWDG counter with value defined in the reload register */
|
/* Reload IWDG counter with value defined in the reload register */
|
||||||
__HAL_IWDG_RELOAD_COUNTER(hiwdg);
|
__HAL_IWDG_RELOAD_COUNTER(hiwdg);
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,6 @@
|
|||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup PWR_register_alias_address PWR Register alias address
|
/** @defgroup PWR_register_alias_address PWR Register alias address
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
@@ -130,17 +129,15 @@ static void PWR_OverloadWfe(void);
|
|||||||
|
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
__NOINLINE
|
__NOINLINE
|
||||||
static void PWR_OverloadWfe(void)
|
static void PWR_OverloadWfe(void) {
|
||||||
{
|
__asm volatile("wfe");
|
||||||
__asm volatile( "wfe" );
|
__asm volatile("nop");
|
||||||
__asm volatile( "nop" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup PWR_Exported_Functions PWR Exported Functions
|
/** @defgroup PWR_Exported_Functions PWR Exported Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
@@ -169,8 +166,7 @@ static void PWR_OverloadWfe(void)
|
|||||||
* @brief Deinitializes the PWR peripheral registers to their default reset values.
|
* @brief Deinitializes the PWR peripheral registers to their default reset values.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_DeInit(void)
|
void HAL_PWR_DeInit(void) {
|
||||||
{
|
|
||||||
__HAL_RCC_PWR_FORCE_RESET();
|
__HAL_RCC_PWR_FORCE_RESET();
|
||||||
__HAL_RCC_PWR_RELEASE_RESET();
|
__HAL_RCC_PWR_RELEASE_RESET();
|
||||||
}
|
}
|
||||||
@@ -182,10 +178,9 @@ void HAL_PWR_DeInit(void)
|
|||||||
* Backup Domain Access should be kept enabled.
|
* Backup Domain Access should be kept enabled.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_EnableBkUpAccess(void)
|
void HAL_PWR_EnableBkUpAccess(void) {
|
||||||
{
|
|
||||||
/* Enable access to RTC and backup registers */
|
/* Enable access to RTC and backup registers */
|
||||||
*(__IO uint32_t *) CR_DBP_BB = (uint32_t)ENABLE;
|
*(__IO uint32_t *)CR_DBP_BB = (uint32_t)ENABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -195,10 +190,9 @@ void HAL_PWR_EnableBkUpAccess(void)
|
|||||||
* Backup Domain Access should be kept enabled.
|
* Backup Domain Access should be kept enabled.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_DisableBkUpAccess(void)
|
void HAL_PWR_DisableBkUpAccess(void) {
|
||||||
{
|
|
||||||
/* Disable access to RTC and backup registers */
|
/* Disable access to RTC and backup registers */
|
||||||
*(__IO uint32_t *) CR_DBP_BB = (uint32_t)DISABLE;
|
*(__IO uint32_t *)CR_DBP_BB = (uint32_t)DISABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -329,8 +323,7 @@ void HAL_PWR_DisableBkUpAccess(void)
|
|||||||
* detection level.
|
* detection level.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
|
void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
|
assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
|
||||||
assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
|
assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
|
||||||
@@ -345,25 +338,21 @@ void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
|
|||||||
__HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();
|
__HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();
|
||||||
|
|
||||||
/* Configure interrupt mode */
|
/* Configure interrupt mode */
|
||||||
if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
|
if ((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT) {
|
||||||
{
|
|
||||||
__HAL_PWR_PVD_EXTI_ENABLE_IT();
|
__HAL_PWR_PVD_EXTI_ENABLE_IT();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Configure event mode */
|
/* Configure event mode */
|
||||||
if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
|
if ((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT) {
|
||||||
{
|
|
||||||
__HAL_PWR_PVD_EXTI_ENABLE_EVENT();
|
__HAL_PWR_PVD_EXTI_ENABLE_EVENT();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Configure the edge */
|
/* Configure the edge */
|
||||||
if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
|
if ((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE) {
|
||||||
{
|
|
||||||
__HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();
|
__HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();
|
||||||
}
|
}
|
||||||
|
|
||||||
if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
|
if ((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE) {
|
||||||
{
|
|
||||||
__HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
|
__HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -372,20 +361,18 @@ void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
|
|||||||
* @brief Enables the Power Voltage Detector(PVD).
|
* @brief Enables the Power Voltage Detector(PVD).
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_EnablePVD(void)
|
void HAL_PWR_EnablePVD(void) {
|
||||||
{
|
|
||||||
/* Enable the power voltage detector */
|
/* Enable the power voltage detector */
|
||||||
*(__IO uint32_t *) CR_PVDE_BB = (uint32_t)ENABLE;
|
*(__IO uint32_t *)CR_PVDE_BB = (uint32_t)ENABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Disables the Power Voltage Detector(PVD).
|
* @brief Disables the Power Voltage Detector(PVD).
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_DisablePVD(void)
|
void HAL_PWR_DisablePVD(void) {
|
||||||
{
|
|
||||||
/* Disable the power voltage detector */
|
/* Disable the power voltage detector */
|
||||||
*(__IO uint32_t *) CR_PVDE_BB = (uint32_t)DISABLE;
|
*(__IO uint32_t *)CR_PVDE_BB = (uint32_t)DISABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -395,12 +382,11 @@ void HAL_PWR_DisablePVD(void)
|
|||||||
* @arg PWR_WAKEUP_PIN1
|
* @arg PWR_WAKEUP_PIN1
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx)
|
void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx) {
|
||||||
{
|
|
||||||
/* Check the parameter */
|
/* Check the parameter */
|
||||||
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
|
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
|
||||||
/* Enable the EWUPx pin */
|
/* Enable the EWUPx pin */
|
||||||
*(__IO uint32_t *) CSR_EWUP_BB(WakeUpPinx) = (uint32_t)ENABLE;
|
*(__IO uint32_t *)CSR_EWUP_BB(WakeUpPinx) = (uint32_t)ENABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -410,12 +396,11 @@ void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx)
|
|||||||
* @arg PWR_WAKEUP_PIN1
|
* @arg PWR_WAKEUP_PIN1
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
|
void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx) {
|
||||||
{
|
|
||||||
/* Check the parameter */
|
/* Check the parameter */
|
||||||
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
|
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
|
||||||
/* Disable the EWUPx pin */
|
/* Disable the EWUPx pin */
|
||||||
*(__IO uint32_t *) CSR_EWUP_BB(WakeUpPinx) = (uint32_t)DISABLE;
|
*(__IO uint32_t *)CSR_EWUP_BB(WakeUpPinx) = (uint32_t)DISABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -430,8 +415,7 @@ void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
|
|||||||
* @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
|
* @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
|
void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
/* No check on Regulator because parameter not used in SLEEP mode */
|
/* No check on Regulator because parameter not used in SLEEP mode */
|
||||||
/* Prevent unused argument(s) compilation warning */
|
/* Prevent unused argument(s) compilation warning */
|
||||||
@@ -443,13 +427,10 @@ void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
|
|||||||
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
|
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
|
||||||
|
|
||||||
/* Select SLEEP mode entry -------------------------------------------------*/
|
/* Select SLEEP mode entry -------------------------------------------------*/
|
||||||
if(SLEEPEntry == PWR_SLEEPENTRY_WFI)
|
if (SLEEPEntry == PWR_SLEEPENTRY_WFI) {
|
||||||
{
|
|
||||||
/* Request Wait For Interrupt */
|
/* Request Wait For Interrupt */
|
||||||
__WFI();
|
__WFI();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Request Wait For Event */
|
/* Request Wait For Event */
|
||||||
__SEV();
|
__SEV();
|
||||||
__WFE();
|
__WFE();
|
||||||
@@ -476,8 +457,7 @@ void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
|
|||||||
* @arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction
|
* @arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
|
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_PWR_REGULATOR(Regulator));
|
assert_param(IS_PWR_REGULATOR(Regulator));
|
||||||
assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
|
assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
|
||||||
@@ -492,13 +472,10 @@ void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
|
|||||||
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
|
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
|
||||||
|
|
||||||
/* Select Stop mode entry --------------------------------------------------*/
|
/* Select Stop mode entry --------------------------------------------------*/
|
||||||
if(STOPEntry == PWR_STOPENTRY_WFI)
|
if (STOPEntry == PWR_STOPENTRY_WFI) {
|
||||||
{
|
|
||||||
/* Request Wait For Interrupt */
|
/* Request Wait For Interrupt */
|
||||||
__WFI();
|
__WFI();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Request Wait For Event */
|
/* Request Wait For Event */
|
||||||
__SEV();
|
__SEV();
|
||||||
PWR_OverloadWfe(); /* WFE redefine locally */
|
PWR_OverloadWfe(); /* WFE redefine locally */
|
||||||
@@ -516,8 +493,7 @@ void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
|
|||||||
* - WKUP pin (PA0) if enabled.
|
* - WKUP pin (PA0) if enabled.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_EnterSTANDBYMode(void)
|
void HAL_PWR_EnterSTANDBYMode(void) {
|
||||||
{
|
|
||||||
/* Select Standby mode */
|
/* Select Standby mode */
|
||||||
SET_BIT(PWR->CR, PWR_CR_PDDS);
|
SET_BIT(PWR->CR, PWR_CR_PDDS);
|
||||||
|
|
||||||
@@ -525,14 +501,13 @@ void HAL_PWR_EnterSTANDBYMode(void)
|
|||||||
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
|
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
|
||||||
|
|
||||||
/* This option is used to ensure that store operations are completed */
|
/* This option is used to ensure that store operations are completed */
|
||||||
#if defined ( __CC_ARM)
|
#if defined(__CC_ARM)
|
||||||
__force_stores();
|
__force_stores();
|
||||||
#endif
|
#endif
|
||||||
/* Request Wait For Interrupt */
|
/* Request Wait For Interrupt */
|
||||||
__WFI();
|
__WFI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Indicates Sleep-On-Exit when returning from Handler mode to Thread mode.
|
* @brief Indicates Sleep-On-Exit when returning from Handler mode to Thread mode.
|
||||||
* @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the processor
|
* @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the processor
|
||||||
@@ -541,63 +516,52 @@ void HAL_PWR_EnterSTANDBYMode(void)
|
|||||||
* interruptions handling.
|
* interruptions handling.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_EnableSleepOnExit(void)
|
void HAL_PWR_EnableSleepOnExit(void) {
|
||||||
{
|
|
||||||
/* Set SLEEPONEXIT bit of Cortex System Control Register */
|
/* Set SLEEPONEXIT bit of Cortex System Control Register */
|
||||||
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
|
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Disables Sleep-On-Exit feature when returning from Handler mode to Thread mode.
|
* @brief Disables Sleep-On-Exit feature when returning from Handler mode to Thread mode.
|
||||||
* @note Clears SLEEPONEXIT bit of SCR register. When this bit is set, the processor
|
* @note Clears SLEEPONEXIT bit of SCR register. When this bit is set, the processor
|
||||||
* re-enters SLEEP mode when an interruption handling is over.
|
* re-enters SLEEP mode when an interruption handling is over.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_DisableSleepOnExit(void)
|
void HAL_PWR_DisableSleepOnExit(void) {
|
||||||
{
|
|
||||||
/* Clear SLEEPONEXIT bit of Cortex System Control Register */
|
/* Clear SLEEPONEXIT bit of Cortex System Control Register */
|
||||||
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
|
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enables CORTEX M3 SEVONPEND bit.
|
* @brief Enables CORTEX M3 SEVONPEND bit.
|
||||||
* @note Sets SEVONPEND bit of SCR register. When this bit is set, this causes
|
* @note Sets SEVONPEND bit of SCR register. When this bit is set, this causes
|
||||||
* WFE to wake up when an interrupt moves from inactive to pended.
|
* WFE to wake up when an interrupt moves from inactive to pended.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_EnableSEVOnPend(void)
|
void HAL_PWR_EnableSEVOnPend(void) {
|
||||||
{
|
|
||||||
/* Set SEVONPEND bit of Cortex System Control Register */
|
/* Set SEVONPEND bit of Cortex System Control Register */
|
||||||
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
|
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Disables CORTEX M3 SEVONPEND bit.
|
* @brief Disables CORTEX M3 SEVONPEND bit.
|
||||||
* @note Clears SEVONPEND bit of SCR register. When this bit is set, this causes
|
* @note Clears SEVONPEND bit of SCR register. When this bit is set, this causes
|
||||||
* WFE to wake up when an interrupt moves from inactive to pended.
|
* WFE to wake up when an interrupt moves from inactive to pended.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_DisableSEVOnPend(void)
|
void HAL_PWR_DisableSEVOnPend(void) {
|
||||||
{
|
|
||||||
/* Clear SEVONPEND bit of Cortex System Control Register */
|
/* Clear SEVONPEND bit of Cortex System Control Register */
|
||||||
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
|
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function handles the PWR PVD interrupt request.
|
* @brief This function handles the PWR PVD interrupt request.
|
||||||
* @note This API should be called under the PVD_IRQHandler().
|
* @note This API should be called under the PVD_IRQHandler().
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_PWR_PVD_IRQHandler(void)
|
void HAL_PWR_PVD_IRQHandler(void) {
|
||||||
{
|
|
||||||
/* Check PWR exti flag */
|
/* Check PWR exti flag */
|
||||||
if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
|
if (__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET) {
|
||||||
{
|
|
||||||
/* PWR PVD interrupt user callback */
|
/* PWR PVD interrupt user callback */
|
||||||
HAL_PWR_PVDCallback();
|
HAL_PWR_PVDCallback();
|
||||||
|
|
||||||
@@ -610,8 +574,7 @@ void HAL_PWR_PVD_IRQHandler(void)
|
|||||||
* @brief PWR PVD interrupt callback
|
* @brief PWR PVD interrupt callback
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_PWR_PVDCallback(void)
|
__weak void HAL_PWR_PVDCallback(void) {
|
||||||
{
|
|
||||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||||
the HAL_PWR_PVDCallback could be implemented in the user file
|
the HAL_PWR_PVDCallback could be implemented in the user file
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -83,7 +83,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/** @defgroup RCC RCC
|
/** @defgroup RCC RCC
|
||||||
* @brief RCC HAL module driver
|
* @brief RCC HAL module driver
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -215,8 +215,7 @@ static void RCC_Delay(uint32_t mdelay);
|
|||||||
* - LSI, LSE and RTC clocks
|
* - LSI, LSE and RTC clocks
|
||||||
* @retval HAL_StatusTypeDef
|
* @retval HAL_StatusTypeDef
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
HAL_StatusTypeDef HAL_RCC_DeInit(void) {
|
||||||
{
|
|
||||||
uint32_t tickstart;
|
uint32_t tickstart;
|
||||||
|
|
||||||
/* Get Start Tick */
|
/* Get Start Tick */
|
||||||
@@ -226,10 +225,8 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
|||||||
SET_BIT(RCC->CR, RCC_CR_HSION);
|
SET_BIT(RCC->CR, RCC_CR_HSION);
|
||||||
|
|
||||||
/* Wait till HSI is ready */
|
/* Wait till HSI is ready */
|
||||||
while (READ_BIT(RCC->CR, RCC_CR_HSIRDY) == RESET)
|
while (READ_BIT(RCC->CR, RCC_CR_HSIRDY) == RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > HSI_TIMEOUT_VALUE) {
|
||||||
if ((HAL_GetTick() - tickstart) > HSI_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,10 +241,8 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
|||||||
CLEAR_REG(RCC->CFGR);
|
CLEAR_REG(RCC->CFGR);
|
||||||
|
|
||||||
/* Wait till clock switch is ready */
|
/* Wait till clock switch is ready */
|
||||||
while (READ_BIT(RCC->CFGR, RCC_CFGR_SWS) != RESET)
|
while (READ_BIT(RCC->CFGR, RCC_CFGR_SWS) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE) {
|
||||||
if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,8 +251,7 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
|||||||
SystemCoreClock = HSI_VALUE;
|
SystemCoreClock = HSI_VALUE;
|
||||||
|
|
||||||
/* Adapt Systick interrupt period */
|
/* Adapt Systick interrupt period */
|
||||||
if(HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
|
if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,10 +262,8 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
|||||||
CLEAR_BIT(RCC->CR, RCC_CR_PLLON);
|
CLEAR_BIT(RCC->CR, RCC_CR_PLLON);
|
||||||
|
|
||||||
/* Wait till PLL is disabled */
|
/* Wait till PLL is disabled */
|
||||||
while (READ_BIT(RCC->CR, RCC_CR_PLLRDY) != RESET)
|
while (READ_BIT(RCC->CR, RCC_CR_PLLRDY) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE) {
|
||||||
if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,10 +278,8 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
|||||||
CLEAR_BIT(RCC->CR, RCC_CR_HSEON | RCC_CR_CSSON);
|
CLEAR_BIT(RCC->CR, RCC_CR_HSEON | RCC_CR_CSSON);
|
||||||
|
|
||||||
/* Wait till HSE is disabled */
|
/* Wait till HSE is disabled */
|
||||||
while (READ_BIT(RCC->CR, RCC_CR_HSERDY) != RESET)
|
while (READ_BIT(RCC->CR, RCC_CR_HSERDY) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE) {
|
||||||
if ((HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,10 +295,8 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
|||||||
CLEAR_BIT(RCC->CR, RCC_CR_PLL2ON);
|
CLEAR_BIT(RCC->CR, RCC_CR_PLL2ON);
|
||||||
|
|
||||||
/* Wait till PLL2 is disabled */
|
/* Wait till PLL2 is disabled */
|
||||||
while (READ_BIT(RCC->CR, RCC_CR_PLL2RDY) != RESET)
|
while (READ_BIT(RCC->CR, RCC_CR_PLL2RDY) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||||
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,10 +310,8 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
|||||||
CLEAR_BIT(RCC->CR, RCC_CR_PLL3ON);
|
CLEAR_BIT(RCC->CR, RCC_CR_PLL3ON);
|
||||||
|
|
||||||
/* Wait till PLL3 is disabled */
|
/* Wait till PLL3 is disabled */
|
||||||
while (READ_BIT(RCC->CR, RCC_CR_PLL3RDY) != RESET)
|
while (READ_BIT(RCC->CR, RCC_CR_PLL3RDY) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE) {
|
||||||
if ((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -360,8 +346,7 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
|||||||
* first and then HSE On or HSE Bypass.
|
* first and then HSE On or HSE Bypass.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) {
|
||||||
{
|
|
||||||
uint32_t tickstart = 0U;
|
uint32_t tickstart = 0U;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -370,33 +355,26 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
|
|
||||||
/*------------------------------- HSE Configuration ------------------------*/
|
/*------------------------------- HSE Configuration ------------------------*/
|
||||||
/*----------------------------- HSI Configuration --------------------------*/
|
/*----------------------------- HSI Configuration --------------------------*/
|
||||||
if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI)
|
if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_RCC_HSI(RCC_OscInitStruct->HSIState));
|
assert_param(IS_RCC_HSI(RCC_OscInitStruct->HSIState));
|
||||||
assert_param(IS_RCC_CALIBRATION_VALUE(RCC_OscInitStruct->HSICalibrationValue));
|
assert_param(IS_RCC_CALIBRATION_VALUE(RCC_OscInitStruct->HSICalibrationValue));
|
||||||
|
|
||||||
/* Check if HSI is used as system clock or as PLL source when PLL is selected as system clock */
|
/* Check if HSI is used as system clock or as PLL source when PLL is selected as system clock */
|
||||||
if((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_HSI)
|
if ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_HSI)
|
||||||
|| ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && (__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSI_DIV2)))
|
|| ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && (__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSI_DIV2))) {
|
||||||
{
|
|
||||||
/* When HSI is used as system clock it will not disabled */
|
/* When HSI is used as system clock it will not disabled */
|
||||||
if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) && (RCC_OscInitStruct->HSIState != RCC_HSI_ON))
|
if ((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) && (RCC_OscInitStruct->HSIState != RCC_HSI_ON)) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
/* Otherwise, just the calibration is allowed */
|
/* Otherwise, just the calibration is allowed */
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
|
/* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
|
||||||
__HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
|
__HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Check the HSI State */
|
/* Check the HSI State */
|
||||||
if(RCC_OscInitStruct->HSIState != RCC_HSI_OFF)
|
if (RCC_OscInitStruct->HSIState != RCC_HSI_OFF) {
|
||||||
{
|
|
||||||
/* Enable the Internal High Speed oscillator (HSI). */
|
/* Enable the Internal High Speed oscillator (HSI). */
|
||||||
__HAL_RCC_HSI_ENABLE();
|
__HAL_RCC_HSI_ENABLE();
|
||||||
|
|
||||||
@@ -404,19 +382,15 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till HSI is ready */
|
/* Wait till HSI is ready */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > HSI_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
|
/* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
|
||||||
__HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
|
__HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Disable the Internal High Speed oscillator (HSI). */
|
/* Disable the Internal High Speed oscillator (HSI). */
|
||||||
__HAL_RCC_HSI_DISABLE();
|
__HAL_RCC_HSI_DISABLE();
|
||||||
|
|
||||||
@@ -424,10 +398,8 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till HSI is disabled */
|
/* Wait till HSI is disabled */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > HSI_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -438,34 +410,25 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
|
|
||||||
/*------------------------------ LSE Configuration -------------------------*/
|
/*------------------------------ LSE Configuration -------------------------*/
|
||||||
|
|
||||||
|
|
||||||
#if defined(RCC_CR_PLL2ON)
|
#if defined(RCC_CR_PLL2ON)
|
||||||
/*-------------------------------- PLL2 Configuration -----------------------*/
|
/*-------------------------------- PLL2 Configuration -----------------------*/
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_RCC_PLL2(RCC_OscInitStruct->PLL2.PLL2State));
|
assert_param(IS_RCC_PLL2(RCC_OscInitStruct->PLL2.PLL2State));
|
||||||
if ((RCC_OscInitStruct->PLL2.PLL2State) != RCC_PLL2_NONE)
|
if ((RCC_OscInitStruct->PLL2.PLL2State) != RCC_PLL2_NONE) {
|
||||||
{
|
|
||||||
/* This bit can not be cleared if the PLL2 clock is used indirectly as system
|
/* This bit can not be cleared if the PLL2 clock is used indirectly as system
|
||||||
clock (i.e. it is used as PLL clock entry that is used as system clock). */
|
clock (i.e. it is used as PLL clock entry that is used as system clock). */
|
||||||
if((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && \
|
if ((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && (__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK)
|
||||||
(__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && \
|
&& ((READ_BIT(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2)) {
|
||||||
((READ_BIT(RCC->CFGR2,RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2))
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
} else {
|
||||||
else
|
if ((RCC_OscInitStruct->PLL2.PLL2State) == RCC_PLL2_ON) {
|
||||||
{
|
|
||||||
if((RCC_OscInitStruct->PLL2.PLL2State) == RCC_PLL2_ON)
|
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_RCC_PLL2_MUL(RCC_OscInitStruct->PLL2.PLL2MUL));
|
assert_param(IS_RCC_PLL2_MUL(RCC_OscInitStruct->PLL2.PLL2MUL));
|
||||||
assert_param(IS_RCC_HSE_PREDIV2(RCC_OscInitStruct->PLL2.HSEPrediv2Value));
|
assert_param(IS_RCC_HSE_PREDIV2(RCC_OscInitStruct->PLL2.HSEPrediv2Value));
|
||||||
|
|
||||||
/* Prediv2 can be written only when the PLLI2S is disabled. */
|
/* Prediv2 can be written only when the PLLI2S is disabled. */
|
||||||
/* Return an error only if new value is different from the programmed value */
|
/* Return an error only if new value is different from the programmed value */
|
||||||
if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL3ON) && \
|
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON) && (__HAL_RCC_HSE_GET_PREDIV2() != RCC_OscInitStruct->PLL2.HSEPrediv2Value)) {
|
||||||
(__HAL_RCC_HSE_GET_PREDIV2() != RCC_OscInitStruct->PLL2.HSEPrediv2Value))
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,10 +439,8 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till PLL2 is disabled */
|
/* Wait till PLL2 is disabled */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -497,16 +458,12 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till PLL2 is ready */
|
/* Wait till PLL2 is ready */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) == RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) == RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Set PREDIV1 source to HSE */
|
/* Set PREDIV1 source to HSE */
|
||||||
CLEAR_BIT(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC);
|
CLEAR_BIT(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC);
|
||||||
|
|
||||||
@@ -517,10 +474,8 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till PLL2 is disabled */
|
/* Wait till PLL2 is disabled */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -532,13 +487,10 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
/*-------------------------------- PLL Configuration -----------------------*/
|
/*-------------------------------- PLL Configuration -----------------------*/
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_RCC_PLL(RCC_OscInitStruct->PLL.PLLState));
|
assert_param(IS_RCC_PLL(RCC_OscInitStruct->PLL.PLLState));
|
||||||
if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE)
|
if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE) {
|
||||||
{
|
|
||||||
/* Check if the PLL is used as system clock or not */
|
/* Check if the PLL is used as system clock or not */
|
||||||
if(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK)
|
if (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK) {
|
||||||
{
|
if ((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_ON) {
|
||||||
if((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_ON)
|
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_RCC_PLLSOURCE(RCC_OscInitStruct->PLL.PLLSource));
|
assert_param(IS_RCC_PLLSOURCE(RCC_OscInitStruct->PLL.PLLSource));
|
||||||
assert_param(IS_RCC_PLL_MUL(RCC_OscInitStruct->PLL.PLLMUL));
|
assert_param(IS_RCC_PLL_MUL(RCC_OscInitStruct->PLL.PLLMUL));
|
||||||
@@ -550,18 +502,15 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till PLL is disabled */
|
/* Wait till PLL is disabled */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Configure the HSE prediv factor --------------------------------*/
|
/* Configure the HSE prediv factor --------------------------------*/
|
||||||
/* It can be written only when the PLL is disabled. Not used in PLL source is different than HSE */
|
/* It can be written only when the PLL is disabled. Not used in PLL source is different than HSE */
|
||||||
if(RCC_OscInitStruct->PLL.PLLSource == RCC_PLLSOURCE_HSE)
|
if (RCC_OscInitStruct->PLL.PLLSource == RCC_PLLSOURCE_HSE) {
|
||||||
{
|
|
||||||
/* Check the parameter */
|
/* Check the parameter */
|
||||||
assert_param(IS_RCC_HSE_PREDIV(RCC_OscInitStruct->HSEPredivValue));
|
assert_param(IS_RCC_HSE_PREDIV(RCC_OscInitStruct->HSEPredivValue));
|
||||||
#if defined(RCC_CFGR2_PREDIV1SRC)
|
#if defined(RCC_CFGR2_PREDIV1SRC)
|
||||||
@@ -576,8 +525,7 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Configure the main PLL clock source and multiplication factors. */
|
/* Configure the main PLL clock source and multiplication factors. */
|
||||||
__HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource,
|
__HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource, RCC_OscInitStruct->PLL.PLLMUL);
|
||||||
RCC_OscInitStruct->PLL.PLLMUL);
|
|
||||||
/* Enable the main PLL. */
|
/* Enable the main PLL. */
|
||||||
__HAL_RCC_PLL_ENABLE();
|
__HAL_RCC_PLL_ENABLE();
|
||||||
|
|
||||||
@@ -585,16 +533,12 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till PLL is ready */
|
/* Wait till PLL is ready */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Disable the main PLL. */
|
/* Disable the main PLL. */
|
||||||
__HAL_RCC_PLL_DISABLE();
|
__HAL_RCC_PLL_DISABLE();
|
||||||
|
|
||||||
@@ -602,17 +546,13 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till PLL is disabled */
|
/* Wait till PLL is disabled */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -643,8 +583,7 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
* currently used as system clock source.
|
* currently used as system clock source.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)
|
HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency) {
|
||||||
{
|
|
||||||
uint32_t tickstart = 0U;
|
uint32_t tickstart = 0U;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -658,32 +597,27 @@ HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, ui
|
|||||||
|
|
||||||
#if defined(FLASH_ACR_LATENCY)
|
#if defined(FLASH_ACR_LATENCY)
|
||||||
/* Increasing the number of wait states because of higher CPU frequency */
|
/* Increasing the number of wait states because of higher CPU frequency */
|
||||||
if(FLatency > (FLASH->ACR & FLASH_ACR_LATENCY))
|
if (FLatency > (FLASH->ACR & FLASH_ACR_LATENCY)) {
|
||||||
{
|
|
||||||
/* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
|
/* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
|
||||||
__HAL_FLASH_SET_LATENCY(FLatency);
|
__HAL_FLASH_SET_LATENCY(FLatency);
|
||||||
|
|
||||||
/* Check that the new number of wait states is taken into account to access the Flash
|
/* Check that the new number of wait states is taken into account to access the Flash
|
||||||
memory by reading the FLASH_ACR register */
|
memory by reading the FLASH_ACR register */
|
||||||
if((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency)
|
if ((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* FLASH_ACR_LATENCY */
|
#endif /* FLASH_ACR_LATENCY */
|
||||||
/*-------------------------- HCLK Configuration --------------------------*/
|
/*-------------------------- HCLK Configuration --------------------------*/
|
||||||
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK)
|
if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK) {
|
||||||
{
|
|
||||||
/* Set the highest APBx dividers in order to ensure that we do not go through
|
/* Set the highest APBx dividers in order to ensure that we do not go through
|
||||||
a non-spec phase whatever we decrease or increase HCLK. */
|
a non-spec phase whatever we decrease or increase HCLK. */
|
||||||
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1)
|
if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1) {
|
||||||
{
|
|
||||||
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, RCC_HCLK_DIV16);
|
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, RCC_HCLK_DIV16);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2)
|
if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2) {
|
||||||
{
|
|
||||||
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, (RCC_HCLK_DIV16 << 3));
|
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, (RCC_HCLK_DIV16 << 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -693,34 +627,27 @@ HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, ui
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------- SYSCLK Configuration ---------------------------*/
|
/*------------------------- SYSCLK Configuration ---------------------------*/
|
||||||
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK)
|
if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK) {
|
||||||
{
|
|
||||||
assert_param(IS_RCC_SYSCLKSOURCE(RCC_ClkInitStruct->SYSCLKSource));
|
assert_param(IS_RCC_SYSCLKSOURCE(RCC_ClkInitStruct->SYSCLKSource));
|
||||||
|
|
||||||
/* HSE is selected as System Clock Source */
|
/* HSE is selected as System Clock Source */
|
||||||
if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
|
if (RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE) {
|
||||||
{
|
|
||||||
/* Check the HSE ready flag */
|
/* Check the HSE ready flag */
|
||||||
if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
|
if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* PLL is selected as System Clock Source */
|
/* PLL is selected as System Clock Source */
|
||||||
else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
|
else if (RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK) {
|
||||||
{
|
|
||||||
/* Check the PLL ready flag */
|
/* Check the PLL ready flag */
|
||||||
if(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
|
if (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* HSI is selected as System Clock Source */
|
/* HSI is selected as System Clock Source */
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Check the HSI ready flag */
|
/* Check the HSI ready flag */
|
||||||
if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET)
|
if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -729,32 +656,21 @@ HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, ui
|
|||||||
/* Get Start Tick */
|
/* Get Start Tick */
|
||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
|
if (RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE) {
|
||||||
{
|
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_HSE) {
|
||||||
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_HSE)
|
if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE) {
|
||||||
{
|
|
||||||
if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK) {
|
||||||
else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
|
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE) {
|
||||||
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK)
|
|
||||||
{
|
|
||||||
if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_HSI) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE) {
|
||||||
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_HSI)
|
|
||||||
{
|
|
||||||
if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -762,39 +678,35 @@ HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, ui
|
|||||||
}
|
}
|
||||||
#if defined(FLASH_ACR_LATENCY)
|
#if defined(FLASH_ACR_LATENCY)
|
||||||
/* Decreasing the number of wait states because of lower CPU frequency */
|
/* Decreasing the number of wait states because of lower CPU frequency */
|
||||||
if(FLatency < (FLASH->ACR & FLASH_ACR_LATENCY))
|
if (FLatency < (FLASH->ACR & FLASH_ACR_LATENCY)) {
|
||||||
{
|
|
||||||
/* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
|
/* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
|
||||||
__HAL_FLASH_SET_LATENCY(FLatency);
|
__HAL_FLASH_SET_LATENCY(FLatency);
|
||||||
|
|
||||||
/* Check that the new number of wait states is taken into account to access the Flash
|
/* Check that the new number of wait states is taken into account to access the Flash
|
||||||
memory by reading the FLASH_ACR register */
|
memory by reading the FLASH_ACR register */
|
||||||
if((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency)
|
if ((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* FLASH_ACR_LATENCY */
|
#endif /* FLASH_ACR_LATENCY */
|
||||||
|
|
||||||
/*-------------------------- PCLK1 Configuration ---------------------------*/
|
/*-------------------------- PCLK1 Configuration ---------------------------*/
|
||||||
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1)
|
if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1) {
|
||||||
{
|
|
||||||
assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB1CLKDivider));
|
assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB1CLKDivider));
|
||||||
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, RCC_ClkInitStruct->APB1CLKDivider);
|
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, RCC_ClkInitStruct->APB1CLKDivider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------- PCLK2 Configuration ---------------------------*/
|
/*-------------------------- PCLK2 Configuration ---------------------------*/
|
||||||
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2)
|
if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2) {
|
||||||
{
|
|
||||||
assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB2CLKDivider));
|
assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB2CLKDivider));
|
||||||
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, ((RCC_ClkInitStruct->APB2CLKDivider) << 3));
|
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, ((RCC_ClkInitStruct->APB2CLKDivider) << 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the SystemCoreClock global variable */
|
/* Update the SystemCoreClock global variable */
|
||||||
SystemCoreClock = HAL_RCC_GetSysClockFreq() >> AHBPrescTable[(RCC->CFGR & RCC_CFGR_HPRE)>> RCC_CFGR_HPRE_Pos];
|
SystemCoreClock = HAL_RCC_GetSysClockFreq() >> AHBPrescTable[(RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos];
|
||||||
|
|
||||||
/* Configure the source of time base considering new system clocks settings*/
|
/* Configure the source of time base considering new system clocks settings*/
|
||||||
HAL_InitTick (TICK_INT_PRIORITY);
|
HAL_InitTick(TICK_INT_PRIORITY);
|
||||||
|
|
||||||
return HAL_OK;
|
return HAL_OK;
|
||||||
}
|
}
|
||||||
@@ -849,8 +761,7 @@ HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, ui
|
|||||||
* @arg @ref RCC_MCODIV_1 no division applied to MCO clock
|
* @arg @ref RCC_MCODIV_1 no division applied to MCO clock
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv)
|
void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv) {
|
||||||
{
|
|
||||||
GPIO_InitTypeDef gpio = {0U};
|
GPIO_InitTypeDef gpio = {0U};
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -886,19 +797,13 @@ void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_M
|
|||||||
* the Cortex-M3 NMI (Non-Maskable Interrupt) exception vector.
|
* the Cortex-M3 NMI (Non-Maskable Interrupt) exception vector.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_RCC_EnableCSS(void)
|
void HAL_RCC_EnableCSS(void) { *(__IO uint32_t *)RCC_CR_CSSON_BB = (uint32_t)ENABLE; }
|
||||||
{
|
|
||||||
*(__IO uint32_t *) RCC_CR_CSSON_BB = (uint32_t)ENABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Disables the Clock Security System.
|
* @brief Disables the Clock Security System.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_RCC_DisableCSS(void)
|
void HAL_RCC_DisableCSS(void) { *(__IO uint32_t *)RCC_CR_CSSON_BB = (uint32_t)DISABLE; }
|
||||||
{
|
|
||||||
*(__IO uint32_t *) RCC_CR_CSSON_BB = (uint32_t)DISABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the SYSCLK frequency
|
* @brief Returns the SYSCLK frequency
|
||||||
@@ -929,8 +834,7 @@ void HAL_RCC_DisableCSS(void)
|
|||||||
*
|
*
|
||||||
* @retval SYSCLK frequency
|
* @retval SYSCLK frequency
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_RCC_GetSysClockFreq(void)
|
uint32_t HAL_RCC_GetSysClockFreq(void) {
|
||||||
{
|
|
||||||
#if defined(RCC_CFGR2_PREDIV1SRC)
|
#if defined(RCC_CFGR2_PREDIV1SRC)
|
||||||
const uint8_t aPLLMULFactorTable[14] = {0, 0, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 13};
|
const uint8_t aPLLMULFactorTable[14] = {0, 0, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 13};
|
||||||
const uint8_t aPredivFactorTable[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
|
const uint8_t aPredivFactorTable[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
|
||||||
@@ -952,8 +856,7 @@ uint32_t HAL_RCC_GetSysClockFreq(void)
|
|||||||
tmpreg = RCC->CFGR;
|
tmpreg = RCC->CFGR;
|
||||||
|
|
||||||
/* Get SYSCLK source -------------------------------------------------------*/
|
/* Get SYSCLK source -------------------------------------------------------*/
|
||||||
switch (tmpreg & RCC_CFGR_SWS)
|
switch (tmpreg & RCC_CFGR_SWS) {
|
||||||
{
|
|
||||||
case RCC_SYSCLKSOURCE_STATUS_HSE: /* HSE used as system clock */
|
case RCC_SYSCLKSOURCE_STATUS_HSE: /* HSE used as system clock */
|
||||||
{
|
{
|
||||||
sysclockfreq = HSE_VALUE;
|
sysclockfreq = HSE_VALUE;
|
||||||
@@ -962,8 +865,7 @@ uint32_t HAL_RCC_GetSysClockFreq(void)
|
|||||||
case RCC_SYSCLKSOURCE_STATUS_PLLCLK: /* PLL used as system clock */
|
case RCC_SYSCLKSOURCE_STATUS_PLLCLK: /* PLL used as system clock */
|
||||||
{
|
{
|
||||||
pllmul = aPLLMULFactorTable[(uint32_t)(tmpreg & RCC_CFGR_PLLMULL) >> RCC_CFGR_PLLMULL_Pos];
|
pllmul = aPLLMULFactorTable[(uint32_t)(tmpreg & RCC_CFGR_PLLMULL) >> RCC_CFGR_PLLMULL_Pos];
|
||||||
if ((tmpreg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2)
|
if ((tmpreg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2) {
|
||||||
{
|
|
||||||
#if defined(RCC_CFGR2_PREDIV1)
|
#if defined(RCC_CFGR2_PREDIV1)
|
||||||
prediv = aPredivFactorTable[(uint32_t)(RCC->CFGR2 & RCC_CFGR2_PREDIV1) >> RCC_CFGR2_PREDIV1_Pos];
|
prediv = aPredivFactorTable[(uint32_t)(RCC->CFGR2 & RCC_CFGR2_PREDIV1) >> RCC_CFGR2_PREDIV1_Pos];
|
||||||
#else
|
#else
|
||||||
@@ -971,33 +873,27 @@ uint32_t HAL_RCC_GetSysClockFreq(void)
|
|||||||
#endif /*RCC_CFGR2_PREDIV1*/
|
#endif /*RCC_CFGR2_PREDIV1*/
|
||||||
#if defined(RCC_CFGR2_PREDIV1SRC)
|
#if defined(RCC_CFGR2_PREDIV1SRC)
|
||||||
|
|
||||||
if(HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC))
|
if (HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC)) {
|
||||||
{
|
|
||||||
/* PLL2 selected as Prediv1 source */
|
/* PLL2 selected as Prediv1 source */
|
||||||
/* PLLCLK = PLL2CLK / PREDIV1 * PLLMUL with PLL2CLK = HSE/PREDIV2 * PLL2MUL */
|
/* PLLCLK = PLL2CLK / PREDIV1 * PLLMUL with PLL2CLK = HSE/PREDIV2 * PLL2MUL */
|
||||||
prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
|
prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
|
||||||
pll2mul = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> RCC_CFGR2_PLL2MUL_Pos) + 2;
|
pll2mul = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> RCC_CFGR2_PLL2MUL_Pos) + 2;
|
||||||
pllclk = (uint32_t)(((uint64_t)HSE_VALUE * (uint64_t)pll2mul * (uint64_t)pllmul) / ((uint64_t)prediv2 * (uint64_t)prediv));
|
pllclk = (uint32_t)(((uint64_t)HSE_VALUE * (uint64_t)pll2mul * (uint64_t)pllmul) / ((uint64_t)prediv2 * (uint64_t)prediv));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
|
/* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
|
||||||
pllclk = (uint32_t)((HSE_VALUE * pllmul) / prediv);
|
pllclk = (uint32_t)((HSE_VALUE * pllmul) / prediv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If PLLMUL was set to 13 means that it was to cover the case PLLMUL 6.5 (avoid using float) */
|
/* If PLLMUL was set to 13 means that it was to cover the case PLLMUL 6.5 (avoid using float) */
|
||||||
/* In this case need to divide pllclk by 2 */
|
/* In this case need to divide pllclk by 2 */
|
||||||
if (pllmul == aPLLMULFactorTable[(uint32_t)(RCC_CFGR_PLLMULL6_5) >> RCC_CFGR_PLLMULL_Pos])
|
if (pllmul == aPLLMULFactorTable[(uint32_t)(RCC_CFGR_PLLMULL6_5) >> RCC_CFGR_PLLMULL_Pos]) {
|
||||||
{
|
|
||||||
pllclk = pllclk / 2;
|
pllclk = pllclk / 2;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
|
/* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
|
||||||
pllclk = (uint32_t)((HSE_VALUE * pllmul) / prediv);
|
pllclk = (uint32_t)((HSE_VALUE * pllmul) / prediv);
|
||||||
#endif /*RCC_CFGR2_PREDIV1SRC*/
|
#endif /*RCC_CFGR2_PREDIV1SRC*/
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* HSI used as PLL clock source : PLLCLK = HSI/2 * PLLMUL */
|
/* HSI used as PLL clock source : PLLCLK = HSI/2 * PLLMUL */
|
||||||
pllclk = (uint32_t)((HSI_VALUE >> 1) * pllmul);
|
pllclk = (uint32_t)((HSI_VALUE >> 1) * pllmul);
|
||||||
}
|
}
|
||||||
@@ -1023,10 +919,7 @@ uint32_t HAL_RCC_GetSysClockFreq(void)
|
|||||||
* and updated within this function
|
* and updated within this function
|
||||||
* @retval HCLK frequency
|
* @retval HCLK frequency
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_RCC_GetHCLKFreq(void)
|
uint32_t HAL_RCC_GetHCLKFreq(void) { return SystemCoreClock; }
|
||||||
{
|
|
||||||
return SystemCoreClock;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the PCLK1 frequency
|
* @brief Returns the PCLK1 frequency
|
||||||
@@ -1034,8 +927,7 @@ uint32_t HAL_RCC_GetHCLKFreq(void)
|
|||||||
* right PCLK1 value. Otherwise, any configuration based on this function will be incorrect.
|
* right PCLK1 value. Otherwise, any configuration based on this function will be incorrect.
|
||||||
* @retval PCLK1 frequency
|
* @retval PCLK1 frequency
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_RCC_GetPCLK1Freq(void)
|
uint32_t HAL_RCC_GetPCLK1Freq(void) {
|
||||||
{
|
|
||||||
/* Get HCLK source and Compute PCLK1 frequency ---------------------------*/
|
/* Get HCLK source and Compute PCLK1 frequency ---------------------------*/
|
||||||
return (HAL_RCC_GetHCLKFreq() >> APBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE1) >> RCC_CFGR_PPRE1_Pos]);
|
return (HAL_RCC_GetHCLKFreq() >> APBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE1) >> RCC_CFGR_PPRE1_Pos]);
|
||||||
}
|
}
|
||||||
@@ -1046,10 +938,9 @@ uint32_t HAL_RCC_GetPCLK1Freq(void)
|
|||||||
* right PCLK2 value. Otherwise, any configuration based on this function will be incorrect.
|
* right PCLK2 value. Otherwise, any configuration based on this function will be incorrect.
|
||||||
* @retval PCLK2 frequency
|
* @retval PCLK2 frequency
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_RCC_GetPCLK2Freq(void)
|
uint32_t HAL_RCC_GetPCLK2Freq(void) {
|
||||||
{
|
|
||||||
/* Get HCLK source and Compute PCLK2 frequency ---------------------------*/
|
/* Get HCLK source and Compute PCLK2 frequency ---------------------------*/
|
||||||
return (HAL_RCC_GetHCLKFreq()>> APBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE2) >> RCC_CFGR_PPRE2_Pos]);
|
return (HAL_RCC_GetHCLKFreq() >> APBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE2) >> RCC_CFGR_PPRE2_Pos]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1059,91 +950,66 @@ uint32_t HAL_RCC_GetPCLK2Freq(void)
|
|||||||
* will be configured.
|
* will be configured.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(RCC_OscInitStruct != NULL);
|
assert_param(RCC_OscInitStruct != NULL);
|
||||||
|
|
||||||
/* Set all possible values for the Oscillator type parameter ---------------*/
|
/* Set all possible values for the Oscillator type parameter ---------------*/
|
||||||
RCC_OscInitStruct->OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI \
|
RCC_OscInitStruct->OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_LSI;
|
||||||
| RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_LSI;
|
|
||||||
|
|
||||||
#if defined(RCC_CFGR2_PREDIV1SRC)
|
#if defined(RCC_CFGR2_PREDIV1SRC)
|
||||||
/* Get the Prediv1 source --------------------------------------------------*/
|
/* Get the Prediv1 source --------------------------------------------------*/
|
||||||
RCC_OscInitStruct->Prediv1Source = READ_BIT(RCC->CFGR2,RCC_CFGR2_PREDIV1SRC);
|
RCC_OscInitStruct->Prediv1Source = READ_BIT(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC);
|
||||||
#endif /* RCC_CFGR2_PREDIV1SRC */
|
#endif /* RCC_CFGR2_PREDIV1SRC */
|
||||||
|
|
||||||
/* Get the HSE configuration -----------------------------------------------*/
|
/* Get the HSE configuration -----------------------------------------------*/
|
||||||
if((RCC->CR &RCC_CR_HSEBYP) == RCC_CR_HSEBYP)
|
if ((RCC->CR & RCC_CR_HSEBYP) == RCC_CR_HSEBYP) {
|
||||||
{
|
|
||||||
RCC_OscInitStruct->HSEState = RCC_HSE_BYPASS;
|
RCC_OscInitStruct->HSEState = RCC_HSE_BYPASS;
|
||||||
}
|
} else if ((RCC->CR & RCC_CR_HSEON) == RCC_CR_HSEON) {
|
||||||
else if((RCC->CR &RCC_CR_HSEON) == RCC_CR_HSEON)
|
|
||||||
{
|
|
||||||
RCC_OscInitStruct->HSEState = RCC_HSE_ON;
|
RCC_OscInitStruct->HSEState = RCC_HSE_ON;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
RCC_OscInitStruct->HSEState = RCC_HSE_OFF;
|
RCC_OscInitStruct->HSEState = RCC_HSE_OFF;
|
||||||
}
|
}
|
||||||
RCC_OscInitStruct->HSEPredivValue = __HAL_RCC_HSE_GET_PREDIV();
|
RCC_OscInitStruct->HSEPredivValue = __HAL_RCC_HSE_GET_PREDIV();
|
||||||
|
|
||||||
/* Get the HSI configuration -----------------------------------------------*/
|
/* Get the HSI configuration -----------------------------------------------*/
|
||||||
if((RCC->CR &RCC_CR_HSION) == RCC_CR_HSION)
|
if ((RCC->CR & RCC_CR_HSION) == RCC_CR_HSION) {
|
||||||
{
|
|
||||||
RCC_OscInitStruct->HSIState = RCC_HSI_ON;
|
RCC_OscInitStruct->HSIState = RCC_HSI_ON;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
RCC_OscInitStruct->HSIState = RCC_HSI_OFF;
|
RCC_OscInitStruct->HSIState = RCC_HSI_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
RCC_OscInitStruct->HSICalibrationValue = (uint32_t)((RCC->CR & RCC_CR_HSITRIM) >> RCC_CR_HSITRIM_Pos);
|
RCC_OscInitStruct->HSICalibrationValue = (uint32_t)((RCC->CR & RCC_CR_HSITRIM) >> RCC_CR_HSITRIM_Pos);
|
||||||
|
|
||||||
/* Get the LSE configuration -----------------------------------------------*/
|
/* Get the LSE configuration -----------------------------------------------*/
|
||||||
if((RCC->BDCR &RCC_BDCR_LSEBYP) == RCC_BDCR_LSEBYP)
|
if ((RCC->BDCR & RCC_BDCR_LSEBYP) == RCC_BDCR_LSEBYP) {
|
||||||
{
|
|
||||||
RCC_OscInitStruct->LSEState = RCC_LSE_BYPASS;
|
RCC_OscInitStruct->LSEState = RCC_LSE_BYPASS;
|
||||||
}
|
} else if ((RCC->BDCR & RCC_BDCR_LSEON) == RCC_BDCR_LSEON) {
|
||||||
else if((RCC->BDCR &RCC_BDCR_LSEON) == RCC_BDCR_LSEON)
|
|
||||||
{
|
|
||||||
RCC_OscInitStruct->LSEState = RCC_LSE_ON;
|
RCC_OscInitStruct->LSEState = RCC_LSE_ON;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
RCC_OscInitStruct->LSEState = RCC_LSE_OFF;
|
RCC_OscInitStruct->LSEState = RCC_LSE_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the LSI configuration -----------------------------------------------*/
|
/* Get the LSI configuration -----------------------------------------------*/
|
||||||
if((RCC->CSR &RCC_CSR_LSION) == RCC_CSR_LSION)
|
if ((RCC->CSR & RCC_CSR_LSION) == RCC_CSR_LSION) {
|
||||||
{
|
|
||||||
RCC_OscInitStruct->LSIState = RCC_LSI_ON;
|
RCC_OscInitStruct->LSIState = RCC_LSI_ON;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
RCC_OscInitStruct->LSIState = RCC_LSI_OFF;
|
RCC_OscInitStruct->LSIState = RCC_LSI_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Get the PLL configuration -----------------------------------------------*/
|
/* Get the PLL configuration -----------------------------------------------*/
|
||||||
if((RCC->CR &RCC_CR_PLLON) == RCC_CR_PLLON)
|
if ((RCC->CR & RCC_CR_PLLON) == RCC_CR_PLLON) {
|
||||||
{
|
|
||||||
RCC_OscInitStruct->PLL.PLLState = RCC_PLL_ON;
|
RCC_OscInitStruct->PLL.PLLState = RCC_PLL_ON;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
RCC_OscInitStruct->PLL.PLLState = RCC_PLL_OFF;
|
RCC_OscInitStruct->PLL.PLLState = RCC_PLL_OFF;
|
||||||
}
|
}
|
||||||
RCC_OscInitStruct->PLL.PLLSource = (uint32_t)(RCC->CFGR & RCC_CFGR_PLLSRC);
|
RCC_OscInitStruct->PLL.PLLSource = (uint32_t)(RCC->CFGR & RCC_CFGR_PLLSRC);
|
||||||
RCC_OscInitStruct->PLL.PLLMUL = (uint32_t)(RCC->CFGR & RCC_CFGR_PLLMULL);
|
RCC_OscInitStruct->PLL.PLLMUL = (uint32_t)(RCC->CFGR & RCC_CFGR_PLLMULL);
|
||||||
#if defined(RCC_CR_PLL2ON)
|
#if defined(RCC_CR_PLL2ON)
|
||||||
/* Get the PLL2 configuration -----------------------------------------------*/
|
/* Get the PLL2 configuration -----------------------------------------------*/
|
||||||
if((RCC->CR &RCC_CR_PLL2ON) == RCC_CR_PLL2ON)
|
if ((RCC->CR & RCC_CR_PLL2ON) == RCC_CR_PLL2ON) {
|
||||||
{
|
|
||||||
RCC_OscInitStruct->PLL2.PLL2State = RCC_PLL2_ON;
|
RCC_OscInitStruct->PLL2.PLL2State = RCC_PLL2_ON;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
RCC_OscInitStruct->PLL2.PLL2State = RCC_PLL2_OFF;
|
RCC_OscInitStruct->PLL2.PLL2State = RCC_PLL2_OFF;
|
||||||
}
|
}
|
||||||
RCC_OscInitStruct->PLL2.HSEPrediv2Value = __HAL_RCC_HSE_GET_PREDIV2();
|
RCC_OscInitStruct->PLL2.HSEPrediv2Value = __HAL_RCC_HSE_GET_PREDIV2();
|
||||||
@@ -1159,8 +1025,7 @@ void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
|||||||
* @param pFLatency Pointer on the Flash Latency.
|
* @param pFLatency Pointer on the Flash Latency.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)
|
void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(RCC_ClkInitStruct != NULL);
|
assert_param(RCC_ClkInitStruct != NULL);
|
||||||
assert_param(pFLatency != NULL);
|
assert_param(pFLatency != NULL);
|
||||||
@@ -1194,11 +1059,9 @@ void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pF
|
|||||||
* @note This API should be called under the NMI_Handler().
|
* @note This API should be called under the NMI_Handler().
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_RCC_NMI_IRQHandler(void)
|
void HAL_RCC_NMI_IRQHandler(void) {
|
||||||
{
|
|
||||||
/* Check RCC CSSF flag */
|
/* Check RCC CSSF flag */
|
||||||
if(__HAL_RCC_GET_IT(RCC_IT_CSS))
|
if (__HAL_RCC_GET_IT(RCC_IT_CSS)) {
|
||||||
{
|
|
||||||
/* RCC Clock Security System interrupt user callback */
|
/* RCC Clock Security System interrupt user callback */
|
||||||
HAL_RCC_CSSCallback();
|
HAL_RCC_CSSCallback();
|
||||||
|
|
||||||
@@ -1212,22 +1075,18 @@ void HAL_RCC_NMI_IRQHandler(void)
|
|||||||
* @param mdelay: specifies the delay time length, in milliseconds.
|
* @param mdelay: specifies the delay time length, in milliseconds.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void RCC_Delay(uint32_t mdelay)
|
static void RCC_Delay(uint32_t mdelay) {
|
||||||
{
|
|
||||||
__IO uint32_t Delay = mdelay * (SystemCoreClock / 8U / 1000U);
|
__IO uint32_t Delay = mdelay * (SystemCoreClock / 8U / 1000U);
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
__NOP();
|
__NOP();
|
||||||
}
|
} while (Delay--);
|
||||||
while (Delay --);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief RCC Clock Security System interrupt callback
|
* @brief RCC Clock Security System interrupt callback
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
__weak void HAL_RCC_CSSCallback(void)
|
__weak void HAL_RCC_CSSCallback(void) {
|
||||||
{
|
|
||||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||||
the HAL_RCC_CSSCallback could be implemented in the user file
|
the HAL_RCC_CSSCallback could be implemented in the user file
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -113,8 +113,7 @@
|
|||||||
*
|
*
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
|
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit) {
|
||||||
{
|
|
||||||
uint32_t tickstart = 0U, temp_reg = 0U;
|
uint32_t tickstart = 0U, temp_reg = 0U;
|
||||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
uint32_t pllactive = 0U;
|
uint32_t pllactive = 0U;
|
||||||
@@ -124,8 +123,7 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
|||||||
assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
|
assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
|
||||||
|
|
||||||
/*------------------------------- RTC/LCD Configuration ------------------------*/
|
/*------------------------------- RTC/LCD Configuration ------------------------*/
|
||||||
if ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC))
|
if ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC)) {
|
||||||
{
|
|
||||||
/* check for RTC Parameters used to output RTCCLK */
|
/* check for RTC Parameters used to output RTCCLK */
|
||||||
assert_param(IS_RCC_RTCCLKSOURCE(PeriphClkInit->RTCClockSelection));
|
assert_param(IS_RCC_RTCCLKSOURCE(PeriphClkInit->RTCClockSelection));
|
||||||
|
|
||||||
@@ -134,24 +132,20 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
|||||||
/* As soon as function is called to change RTC clock source, activation of the
|
/* As soon as function is called to change RTC clock source, activation of the
|
||||||
power domain is done. */
|
power domain is done. */
|
||||||
/* Requires to enable write access to Backup Domain of necessary */
|
/* Requires to enable write access to Backup Domain of necessary */
|
||||||
if(__HAL_RCC_PWR_IS_CLK_DISABLED())
|
if (__HAL_RCC_PWR_IS_CLK_DISABLED()) {
|
||||||
{
|
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
pwrclkchanged = SET;
|
pwrclkchanged = SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
|
if (HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP)) {
|
||||||
{
|
|
||||||
/* Enable write access to Backup domain */
|
/* Enable write access to Backup domain */
|
||||||
SET_BIT(PWR->CR, PWR_CR_DBP);
|
SET_BIT(PWR->CR, PWR_CR_DBP);
|
||||||
|
|
||||||
/* Wait for Backup domain Write protection disable */
|
/* Wait for Backup domain Write protection disable */
|
||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
while(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
|
while (HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP)) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,8 +153,7 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
|||||||
|
|
||||||
/* Reset the Backup domain only if the RTC Clock source selection is modified from reset value */
|
/* Reset the Backup domain only if the RTC Clock source selection is modified from reset value */
|
||||||
temp_reg = (RCC->BDCR & RCC_BDCR_RTCSEL);
|
temp_reg = (RCC->BDCR & RCC_BDCR_RTCSEL);
|
||||||
if((temp_reg != 0x00000000U) && (temp_reg != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL)))
|
if ((temp_reg != 0x00000000U) && (temp_reg != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL))) {
|
||||||
{
|
|
||||||
/* Store the content of BDCR register before the reset of Backup Domain */
|
/* Store the content of BDCR register before the reset of Backup Domain */
|
||||||
temp_reg = (RCC->BDCR & ~(RCC_BDCR_RTCSEL));
|
temp_reg = (RCC->BDCR & ~(RCC_BDCR_RTCSEL));
|
||||||
/* RTC Clock selection can be changed only if the Backup Domain is reset */
|
/* RTC Clock selection can be changed only if the Backup Domain is reset */
|
||||||
@@ -170,16 +163,13 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
|||||||
RCC->BDCR = temp_reg;
|
RCC->BDCR = temp_reg;
|
||||||
|
|
||||||
/* Wait for LSERDY if LSE was enabled */
|
/* Wait for LSERDY if LSE was enabled */
|
||||||
if (HAL_IS_BIT_SET(temp_reg, RCC_BDCR_LSEON))
|
if (HAL_IS_BIT_SET(temp_reg, RCC_BDCR_LSEON)) {
|
||||||
{
|
|
||||||
/* Get Start Tick */
|
/* Get Start Tick */
|
||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till LSE is ready */
|
/* Wait till LSE is ready */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,15 +178,13 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
|||||||
__HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
|
__HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
|
||||||
|
|
||||||
/* Require to disable power clock if necessary */
|
/* Require to disable power clock if necessary */
|
||||||
if(pwrclkchanged == SET)
|
if (pwrclkchanged == SET) {
|
||||||
{
|
|
||||||
__HAL_RCC_PWR_CLK_DISABLE();
|
__HAL_RCC_PWR_CLK_DISABLE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------ ADC clock Configuration ------------------*/
|
/*------------------------------ ADC clock Configuration ------------------*/
|
||||||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC)
|
if (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_RCC_ADCPLLCLK_DIV(PeriphClkInit->AdcClockSelection));
|
assert_param(IS_RCC_ADCPLLCLK_DIV(PeriphClkInit->AdcClockSelection));
|
||||||
|
|
||||||
@@ -206,8 +194,7 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
|||||||
|
|
||||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
/*------------------------------ I2S2 Configuration ------------------------*/
|
/*------------------------------ I2S2 Configuration ------------------------*/
|
||||||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S2) == RCC_PERIPHCLK_I2S2)
|
if (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S2) == RCC_PERIPHCLK_I2S2) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_RCC_I2S2CLKSOURCE(PeriphClkInit->I2s2ClockSelection));
|
assert_param(IS_RCC_I2S2CLKSOURCE(PeriphClkInit->I2s2ClockSelection));
|
||||||
|
|
||||||
@@ -216,8 +203,7 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------ I2S3 Configuration ------------------------*/
|
/*------------------------------ I2S3 Configuration ------------------------*/
|
||||||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S3) == RCC_PERIPHCLK_I2S3)
|
if (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S3) == RCC_PERIPHCLK_I2S3) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_RCC_I2S3CLKSOURCE(PeriphClkInit->I2s3ClockSelection));
|
assert_param(IS_RCC_I2S3CLKSOURCE(PeriphClkInit->I2s3ClockSelection));
|
||||||
|
|
||||||
@@ -227,27 +213,22 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
|||||||
|
|
||||||
/*------------------------------ PLL I2S Configuration ----------------------*/
|
/*------------------------------ PLL I2S Configuration ----------------------*/
|
||||||
/* Check that PLLI2S need to be enabled */
|
/* Check that PLLI2S need to be enabled */
|
||||||
if (HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_I2S2SRC) || HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_I2S3SRC))
|
if (HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_I2S2SRC) || HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_I2S3SRC)) {
|
||||||
{
|
|
||||||
/* Update flag to indicate that PLL I2S should be active */
|
/* Update flag to indicate that PLL I2S should be active */
|
||||||
pllactive = 1;
|
pllactive = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if PLL I2S need to be enabled */
|
/* Check if PLL I2S need to be enabled */
|
||||||
if (pllactive == 1)
|
if (pllactive == 1) {
|
||||||
{
|
|
||||||
/* Enable PLL I2S only if not active */
|
/* Enable PLL I2S only if not active */
|
||||||
if (HAL_IS_BIT_CLR(RCC->CR, RCC_CR_PLL3ON))
|
if (HAL_IS_BIT_CLR(RCC->CR, RCC_CR_PLL3ON)) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_RCC_PLLI2S_MUL(PeriphClkInit->PLLI2S.PLLI2SMUL));
|
assert_param(IS_RCC_PLLI2S_MUL(PeriphClkInit->PLLI2S.PLLI2SMUL));
|
||||||
assert_param(IS_RCC_HSE_PREDIV2(PeriphClkInit->PLLI2S.HSEPrediv2Value));
|
assert_param(IS_RCC_HSE_PREDIV2(PeriphClkInit->PLLI2S.HSEPrediv2Value));
|
||||||
|
|
||||||
/* Prediv2 can be written only when the PLL2 is disabled. */
|
/* Prediv2 can be written only when the PLL2 is disabled. */
|
||||||
/* Return an error only if new value is different from the programmed value */
|
/* Return an error only if new value is different from the programmed value */
|
||||||
if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL2ON) && \
|
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2ON) && (__HAL_RCC_HSE_GET_PREDIV2() != PeriphClkInit->PLLI2S.HSEPrediv2Value)) {
|
||||||
(__HAL_RCC_HSE_GET_PREDIV2() != PeriphClkInit->PLLI2S.HSEPrediv2Value))
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,31 +245,23 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till PLLI2S is ready */
|
/* Wait till PLLI2S is ready */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Return an error only if user wants to change the PLLI2SMUL whereas PLLI2S is active */
|
/* Return an error only if user wants to change the PLLI2SMUL whereas PLLI2S is active */
|
||||||
if (READ_BIT(RCC->CFGR2, RCC_CFGR2_PLL3MUL) != PeriphClkInit->PLLI2S.PLLI2SMUL)
|
if (READ_BIT(RCC->CFGR2, RCC_CFGR2_PLL3MUL) != PeriphClkInit->PLLI2S.PLLI2SMUL) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* STM32F105xC || STM32F107xC */
|
#endif /* STM32F105xC || STM32F107xC */
|
||||||
|
|
||||||
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
|
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
|| defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
|
|
||||||
|| defined(STM32F105xC) || defined(STM32F107xC)
|
|
||||||
/*------------------------------ USB clock Configuration ------------------*/
|
/*------------------------------ USB clock Configuration ------------------*/
|
||||||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB)
|
if (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_RCC_USBPLLCLK_DIV(PeriphClkInit->UsbClockSelection));
|
assert_param(IS_RCC_USBPLLCLK_DIV(PeriphClkInit->UsbClockSelection));
|
||||||
|
|
||||||
@@ -307,8 +280,7 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
|||||||
* returns the configuration information for the Extended Peripherals clocks(RTC, I2S, ADC clocks).
|
* returns the configuration information for the Extended Peripherals clocks(RTC, I2S, ADC clocks).
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
|
void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit) {
|
||||||
{
|
|
||||||
uint32_t srcclk = 0U;
|
uint32_t srcclk = 0U;
|
||||||
|
|
||||||
/* Set all possible values for the extended clock type parameter------------*/
|
/* Set all possible values for the extended clock type parameter------------*/
|
||||||
@@ -345,9 +317,7 @@ void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
|
|||||||
|
|
||||||
#endif /* STM32F103xE || STM32F103xG */
|
#endif /* STM32F103xE || STM32F103xG */
|
||||||
|
|
||||||
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
|
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
|| defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
|
|
||||||
|| defined(STM32F105xC) || defined(STM32F107xC)
|
|
||||||
/* Get the USB clock configuration -----------------------------------------*/
|
/* Get the USB clock configuration -----------------------------------------*/
|
||||||
PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_USB;
|
PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_USB;
|
||||||
PeriphClkInit->UsbClockSelection = __HAL_RCC_GET_USB_SOURCE();
|
PeriphClkInit->UsbClockSelection = __HAL_RCC_GET_USB_SOURCE();
|
||||||
@@ -400,8 +370,7 @@ void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
|
|||||||
@endif
|
@endif
|
||||||
* @retval Frequency in Hz (0: means that no available frequency for the peripheral)
|
* @retval Frequency in Hz (0: means that no available frequency for the peripheral)
|
||||||
*/
|
*/
|
||||||
uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk) {
|
||||||
{
|
|
||||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
const uint8_t aPLLMULFactorTable[14] = {0, 0, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 13};
|
const uint8_t aPLLMULFactorTable[14] = {0, 0, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 13};
|
||||||
const uint8_t aPredivFactorTable[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
|
const uint8_t aPredivFactorTable[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
|
||||||
@@ -409,8 +378,7 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
|||||||
uint32_t prediv1 = 0U, pllclk = 0U, pllmul = 0U;
|
uint32_t prediv1 = 0U, pllclk = 0U, pllmul = 0U;
|
||||||
uint32_t pll2mul = 0U, pll3mul = 0U, prediv2 = 0U;
|
uint32_t pll2mul = 0U, pll3mul = 0U, prediv2 = 0U;
|
||||||
#endif /* STM32F105xC || STM32F107xC */
|
#endif /* STM32F105xC || STM32F107xC */
|
||||||
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6) || \
|
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||||
defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)
|
|
||||||
const uint8_t aPLLMULFactorTable[16] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16};
|
const uint8_t aPLLMULFactorTable[16] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16};
|
||||||
const uint8_t aPredivFactorTable[2] = {1, 2};
|
const uint8_t aPredivFactorTable[2] = {1, 2};
|
||||||
|
|
||||||
@@ -421,60 +389,46 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
|||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_RCC_PERIPHCLOCK(PeriphClk));
|
assert_param(IS_RCC_PERIPHCLOCK(PeriphClk));
|
||||||
|
|
||||||
switch (PeriphClk)
|
switch (PeriphClk) {
|
||||||
{
|
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
|
case RCC_PERIPHCLK_USB: {
|
||||||
|| defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
|
|
||||||
|| defined(STM32F105xC) || defined(STM32F107xC)
|
|
||||||
case RCC_PERIPHCLK_USB:
|
|
||||||
{
|
|
||||||
/* Get RCC configuration ------------------------------------------------------*/
|
/* Get RCC configuration ------------------------------------------------------*/
|
||||||
temp_reg = RCC->CFGR;
|
temp_reg = RCC->CFGR;
|
||||||
|
|
||||||
/* Check if PLL is enabled */
|
/* Check if PLL is enabled */
|
||||||
if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLLON))
|
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLLON)) {
|
||||||
{
|
|
||||||
pllmul = aPLLMULFactorTable[(uint32_t)(temp_reg & RCC_CFGR_PLLMULL) >> RCC_CFGR_PLLMULL_Pos];
|
pllmul = aPLLMULFactorTable[(uint32_t)(temp_reg & RCC_CFGR_PLLMULL) >> RCC_CFGR_PLLMULL_Pos];
|
||||||
if ((temp_reg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2)
|
if ((temp_reg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2) {
|
||||||
{
|
#if defined(STM32F105xC) || defined(STM32F107xC) || defined(STM32F100xB) || defined(STM32F100xE)
|
||||||
#if defined(STM32F105xC) || defined(STM32F107xC) || defined(STM32F100xB)\
|
|
||||||
|| defined(STM32F100xE)
|
|
||||||
prediv1 = aPredivFactorTable[(uint32_t)(RCC->CFGR2 & RCC_CFGR2_PREDIV1) >> RCC_CFGR2_PREDIV1_Pos];
|
prediv1 = aPredivFactorTable[(uint32_t)(RCC->CFGR2 & RCC_CFGR2_PREDIV1) >> RCC_CFGR2_PREDIV1_Pos];
|
||||||
#else
|
#else
|
||||||
prediv1 = aPredivFactorTable[(uint32_t)(RCC->CFGR & RCC_CFGR_PLLXTPRE) >> RCC_CFGR_PLLXTPRE_Pos];
|
prediv1 = aPredivFactorTable[(uint32_t)(RCC->CFGR & RCC_CFGR_PLLXTPRE) >> RCC_CFGR_PLLXTPRE_Pos];
|
||||||
#endif /* STM32F105xC || STM32F107xC || STM32F100xB || STM32F100xE */
|
#endif /* STM32F105xC || STM32F107xC || STM32F100xB || STM32F100xE */
|
||||||
|
|
||||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
if(HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC))
|
if (HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC)) {
|
||||||
{
|
|
||||||
/* PLL2 selected as Prediv1 source */
|
/* PLL2 selected as Prediv1 source */
|
||||||
/* PLLCLK = PLL2CLK / PREDIV1 * PLLMUL with PLL2CLK = HSE/PREDIV2 * PLL2MUL */
|
/* PLLCLK = PLL2CLK / PREDIV1 * PLLMUL with PLL2CLK = HSE/PREDIV2 * PLL2MUL */
|
||||||
prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
|
prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
|
||||||
pll2mul = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> RCC_CFGR2_PLL2MUL_Pos) + 2;
|
pll2mul = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> RCC_CFGR2_PLL2MUL_Pos) + 2;
|
||||||
pllclk = (uint32_t)((((HSE_VALUE / prediv2) * pll2mul) / prediv1) * pllmul);
|
pllclk = (uint32_t)((((HSE_VALUE / prediv2) * pll2mul) / prediv1) * pllmul);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
|
/* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
|
||||||
pllclk = (uint32_t)((HSE_VALUE / prediv1) * pllmul);
|
pllclk = (uint32_t)((HSE_VALUE / prediv1) * pllmul);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If PLLMUL was set to 13 means that it was to cover the case PLLMUL 6.5 (avoid using float) */
|
/* If PLLMUL was set to 13 means that it was to cover the case PLLMUL 6.5 (avoid using float) */
|
||||||
/* In this case need to divide pllclk by 2 */
|
/* In this case need to divide pllclk by 2 */
|
||||||
if (pllmul == aPLLMULFactorTable[(uint32_t)(RCC_CFGR_PLLMULL6_5) >> RCC_CFGR_PLLMULL_Pos])
|
if (pllmul == aPLLMULFactorTable[(uint32_t)(RCC_CFGR_PLLMULL6_5) >> RCC_CFGR_PLLMULL_Pos]) {
|
||||||
{
|
|
||||||
pllclk = pllclk / 2;
|
pllclk = pllclk / 2;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if ((temp_reg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2)
|
if ((temp_reg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2) {
|
||||||
{
|
|
||||||
/* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
|
/* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
|
||||||
pllclk = (uint32_t)((HSE_VALUE / prediv1) * pllmul);
|
pllclk = (uint32_t)((HSE_VALUE / prediv1) * pllmul);
|
||||||
}
|
}
|
||||||
#endif /* STM32F105xC || STM32F107xC */
|
#endif /* STM32F105xC || STM32F107xC */
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* HSI used as PLL clock source : PLLCLK = HSI/2 * PLLMUL */
|
/* HSI used as PLL clock source : PLLCLK = HSI/2 * PLLMUL */
|
||||||
pllclk = (uint32_t)((HSI_VALUE >> 1) * pllmul);
|
pllclk = (uint32_t)((HSI_VALUE >> 1) * pllmul);
|
||||||
}
|
}
|
||||||
@@ -482,25 +436,19 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
|||||||
/* Calcul of the USB frequency*/
|
/* Calcul of the USB frequency*/
|
||||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
/* USBCLK = PLLVCO = (2 x PLLCLK) / USB prescaler */
|
/* USBCLK = PLLVCO = (2 x PLLCLK) / USB prescaler */
|
||||||
if (__HAL_RCC_GET_USB_SOURCE() == RCC_USBCLKSOURCE_PLL_DIV2)
|
if (__HAL_RCC_GET_USB_SOURCE() == RCC_USBCLKSOURCE_PLL_DIV2) {
|
||||||
{
|
|
||||||
/* Prescaler of 2 selected for USB */
|
/* Prescaler of 2 selected for USB */
|
||||||
frequency = pllclk;
|
frequency = pllclk;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Prescaler of 3 selected for USB */
|
/* Prescaler of 3 selected for USB */
|
||||||
frequency = (2 * pllclk) / 3;
|
frequency = (2 * pllclk) / 3;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* USBCLK = PLLCLK / USB prescaler */
|
/* USBCLK = PLLCLK / USB prescaler */
|
||||||
if (__HAL_RCC_GET_USB_SOURCE() == RCC_USBCLKSOURCE_PLL)
|
if (__HAL_RCC_GET_USB_SOURCE() == RCC_USBCLKSOURCE_PLL) {
|
||||||
{
|
|
||||||
/* No prescaler selected for USB */
|
/* No prescaler selected for USB */
|
||||||
frequency = pllclk;
|
frequency = pllclk;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Prescaler of 1.5 selected for USB */
|
/* Prescaler of 1.5 selected for USB */
|
||||||
frequency = (pllclk * 2) / 3;
|
frequency = (pllclk * 2) / 3;
|
||||||
}
|
}
|
||||||
@@ -510,22 +458,17 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
|||||||
}
|
}
|
||||||
#endif /* STM32F102x6 || STM32F102xB || STM32F103x6 || STM32F103xB || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
|
#endif /* STM32F102x6 || STM32F102xB || STM32F103x6 || STM32F103xB || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
|
||||||
#if defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
#if defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
case RCC_PERIPHCLK_I2S2:
|
case RCC_PERIPHCLK_I2S2: {
|
||||||
{
|
|
||||||
#if defined(STM32F103xE) || defined(STM32F103xG)
|
#if defined(STM32F103xE) || defined(STM32F103xG)
|
||||||
/* SYSCLK used as source clock for I2S2 */
|
/* SYSCLK used as source clock for I2S2 */
|
||||||
frequency = HAL_RCC_GetSysClockFreq();
|
frequency = HAL_RCC_GetSysClockFreq();
|
||||||
#else
|
#else
|
||||||
if (__HAL_RCC_GET_I2S2_SOURCE() == RCC_I2S2CLKSOURCE_SYSCLK)
|
if (__HAL_RCC_GET_I2S2_SOURCE() == RCC_I2S2CLKSOURCE_SYSCLK) {
|
||||||
{
|
|
||||||
/* SYSCLK used as source clock for I2S2 */
|
/* SYSCLK used as source clock for I2S2 */
|
||||||
frequency = HAL_RCC_GetSysClockFreq();
|
frequency = HAL_RCC_GetSysClockFreq();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Check if PLLI2S is enabled */
|
/* Check if PLLI2S is enabled */
|
||||||
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON))
|
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON)) {
|
||||||
{
|
|
||||||
/* PLLI2SVCO = 2 * PLLI2SCLK = 2 * (HSE/PREDIV2 * PLL3MUL) */
|
/* PLLI2SVCO = 2 * PLLI2SCLK = 2 * (HSE/PREDIV2 * PLL3MUL) */
|
||||||
prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
|
prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
|
||||||
pll3mul = ((RCC->CFGR2 & RCC_CFGR2_PLL3MUL) >> RCC_CFGR2_PLL3MUL_Pos) + 2;
|
pll3mul = ((RCC->CFGR2 & RCC_CFGR2_PLL3MUL) >> RCC_CFGR2_PLL3MUL_Pos) + 2;
|
||||||
@@ -535,22 +478,17 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
|||||||
#endif /* STM32F103xE || STM32F103xG */
|
#endif /* STM32F103xE || STM32F103xG */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RCC_PERIPHCLK_I2S3:
|
case RCC_PERIPHCLK_I2S3: {
|
||||||
{
|
|
||||||
#if defined(STM32F103xE) || defined(STM32F103xG)
|
#if defined(STM32F103xE) || defined(STM32F103xG)
|
||||||
/* SYSCLK used as source clock for I2S3 */
|
/* SYSCLK used as source clock for I2S3 */
|
||||||
frequency = HAL_RCC_GetSysClockFreq();
|
frequency = HAL_RCC_GetSysClockFreq();
|
||||||
#else
|
#else
|
||||||
if (__HAL_RCC_GET_I2S3_SOURCE() == RCC_I2S3CLKSOURCE_SYSCLK)
|
if (__HAL_RCC_GET_I2S3_SOURCE() == RCC_I2S3CLKSOURCE_SYSCLK) {
|
||||||
{
|
|
||||||
/* SYSCLK used as source clock for I2S3 */
|
/* SYSCLK used as source clock for I2S3 */
|
||||||
frequency = HAL_RCC_GetSysClockFreq();
|
frequency = HAL_RCC_GetSysClockFreq();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Check if PLLI2S is enabled */
|
/* Check if PLLI2S is enabled */
|
||||||
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON))
|
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON)) {
|
||||||
{
|
|
||||||
/* PLLI2SVCO = 2 * PLLI2SCLK = 2 * (HSE/PREDIV2 * PLL3MUL) */
|
/* PLLI2SVCO = 2 * PLLI2SCLK = 2 * (HSE/PREDIV2 * PLL3MUL) */
|
||||||
prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
|
prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
|
||||||
pll3mul = ((RCC->CFGR2 & RCC_CFGR2_PLL3MUL) >> RCC_CFGR2_PLL3MUL_Pos) + 2;
|
pll3mul = ((RCC->CFGR2 & RCC_CFGR2_PLL3MUL) >> RCC_CFGR2_PLL3MUL_Pos) + 2;
|
||||||
@@ -561,43 +499,35 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif /* STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
|
#endif /* STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
|
||||||
case RCC_PERIPHCLK_RTC:
|
case RCC_PERIPHCLK_RTC: {
|
||||||
{
|
|
||||||
/* Get RCC BDCR configuration ------------------------------------------------------*/
|
/* Get RCC BDCR configuration ------------------------------------------------------*/
|
||||||
temp_reg = RCC->BDCR;
|
temp_reg = RCC->BDCR;
|
||||||
|
|
||||||
/* Check if LSE is ready if RTC clock selection is LSE */
|
/* Check if LSE is ready if RTC clock selection is LSE */
|
||||||
if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_LSE) && (HAL_IS_BIT_SET(temp_reg, RCC_BDCR_LSERDY)))
|
if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_LSE) && (HAL_IS_BIT_SET(temp_reg, RCC_BDCR_LSERDY))) {
|
||||||
{
|
|
||||||
frequency = LSE_VALUE;
|
frequency = LSE_VALUE;
|
||||||
}
|
}
|
||||||
/* Check if LSI is ready if RTC clock selection is LSI */
|
/* Check if LSI is ready if RTC clock selection is LSI */
|
||||||
else if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_LSI) && (HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY)))
|
else if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_LSI) && (HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY))) {
|
||||||
{
|
|
||||||
frequency = LSI_VALUE;
|
frequency = LSI_VALUE;
|
||||||
}
|
} else if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_HSE_DIV128) && (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY))) {
|
||||||
else if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_HSE_DIV128) && (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)))
|
|
||||||
{
|
|
||||||
frequency = HSE_VALUE / 128U;
|
frequency = HSE_VALUE / 128U;
|
||||||
}
|
}
|
||||||
/* Clock not enabled for RTC*/
|
/* Clock not enabled for RTC*/
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
frequency = 0U;
|
frequency = 0U;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RCC_PERIPHCLK_ADC:
|
case RCC_PERIPHCLK_ADC: {
|
||||||
{
|
|
||||||
frequency = HAL_RCC_GetPCLK2Freq() / (((__HAL_RCC_GET_ADC_SOURCE() >> RCC_CFGR_ADCPRE_Pos) + 1) * 2);
|
frequency = HAL_RCC_GetPCLK2Freq() / (((__HAL_RCC_GET_ADC_SOURCE() >> RCC_CFGR_ADCPRE_Pos) + 1) * 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(frequency);
|
return (frequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -626,22 +556,18 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
|||||||
* @note The PLLI2S configuration not modified if used by I2S2 or I2S3 Interface.
|
* @note The PLLI2S configuration not modified if used by I2S2 or I2S3 Interface.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit)
|
HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit) {
|
||||||
{
|
|
||||||
uint32_t tickstart = 0U;
|
uint32_t tickstart = 0U;
|
||||||
|
|
||||||
/* Check that PLL I2S has not been already enabled by I2S2 or I2S3*/
|
/* Check that PLL I2S has not been already enabled by I2S2 or I2S3*/
|
||||||
if (HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S2SRC) && HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S3SRC))
|
if (HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S2SRC) && HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S3SRC)) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_RCC_PLLI2S_MUL(PLLI2SInit->PLLI2SMUL));
|
assert_param(IS_RCC_PLLI2S_MUL(PLLI2SInit->PLLI2SMUL));
|
||||||
assert_param(IS_RCC_HSE_PREDIV2(PLLI2SInit->HSEPrediv2Value));
|
assert_param(IS_RCC_HSE_PREDIV2(PLLI2SInit->HSEPrediv2Value));
|
||||||
|
|
||||||
/* Prediv2 can be written only when the PLL2 is disabled. */
|
/* Prediv2 can be written only when the PLL2 is disabled. */
|
||||||
/* Return an error only if new value is different from the programmed value */
|
/* Return an error only if new value is different from the programmed value */
|
||||||
if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL2ON) && \
|
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2ON) && (__HAL_RCC_HSE_GET_PREDIV2() != PLLI2SInit->HSEPrediv2Value)) {
|
||||||
(__HAL_RCC_HSE_GET_PREDIV2() != PLLI2SInit->HSEPrediv2Value))
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -652,10 +578,8 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till PLLI2S is ready */
|
/* Wait till PLLI2S is ready */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -663,7 +587,6 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit)
|
|||||||
/* Configure the HSE prediv2 factor --------------------------------*/
|
/* Configure the HSE prediv2 factor --------------------------------*/
|
||||||
__HAL_RCC_HSE_PREDIV2_CONFIG(PLLI2SInit->HSEPrediv2Value);
|
__HAL_RCC_HSE_PREDIV2_CONFIG(PLLI2SInit->HSEPrediv2Value);
|
||||||
|
|
||||||
|
|
||||||
/* Configure the main PLLI2S multiplication factors. */
|
/* Configure the main PLLI2S multiplication factors. */
|
||||||
__HAL_RCC_PLLI2S_CONFIG(PLLI2SInit->PLLI2SMUL);
|
__HAL_RCC_PLLI2S_CONFIG(PLLI2SInit->PLLI2SMUL);
|
||||||
|
|
||||||
@@ -674,16 +597,12 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till PLLI2S is ready */
|
/* Wait till PLLI2S is ready */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* PLLI2S cannot be modified as already used by I2S2 or I2S3 */
|
/* PLLI2S cannot be modified as already used by I2S2 or I2S3 */
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
@@ -696,13 +615,11 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit)
|
|||||||
* @note PLLI2S is not disabled if used by I2S2 or I2S3 Interface.
|
* @note PLLI2S is not disabled if used by I2S2 or I2S3 Interface.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_RCCEx_DisablePLLI2S(void)
|
HAL_StatusTypeDef HAL_RCCEx_DisablePLLI2S(void) {
|
||||||
{
|
|
||||||
uint32_t tickstart = 0U;
|
uint32_t tickstart = 0U;
|
||||||
|
|
||||||
/* Disable PLL I2S as not requested by I2S2 or I2S3*/
|
/* Disable PLL I2S as not requested by I2S2 or I2S3*/
|
||||||
if (HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S2SRC) && HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S3SRC))
|
if (HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S2SRC) && HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S3SRC)) {
|
||||||
{
|
|
||||||
/* Disable the main PLLI2S. */
|
/* Disable the main PLLI2S. */
|
||||||
__HAL_RCC_PLLI2S_DISABLE();
|
__HAL_RCC_PLLI2S_DISABLE();
|
||||||
|
|
||||||
@@ -710,16 +627,12 @@ HAL_StatusTypeDef HAL_RCCEx_DisablePLLI2S(void)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till PLLI2S is ready */
|
/* Wait till PLLI2S is ready */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* PLLI2S is currently used by I2S2 or I2S3. Cannot be disabled.*/
|
/* PLLI2S is currently used by I2S2 or I2S3. Cannot be disabled.*/
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
@@ -752,29 +665,22 @@ HAL_StatusTypeDef HAL_RCCEx_DisablePLLI2S(void)
|
|||||||
* @note The PLL2 configuration not modified if used indirectly as system clock.
|
* @note The PLL2 configuration not modified if used indirectly as system clock.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_RCCEx_EnablePLL2(RCC_PLL2InitTypeDef *PLL2Init)
|
HAL_StatusTypeDef HAL_RCCEx_EnablePLL2(RCC_PLL2InitTypeDef *PLL2Init) {
|
||||||
{
|
|
||||||
uint32_t tickstart = 0U;
|
uint32_t tickstart = 0U;
|
||||||
|
|
||||||
/* This bit can not be cleared if the PLL2 clock is used indirectly as system
|
/* This bit can not be cleared if the PLL2 clock is used indirectly as system
|
||||||
clock (i.e. it is used as PLL clock entry that is used as system clock). */
|
clock (i.e. it is used as PLL clock entry that is used as system clock). */
|
||||||
if((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && \
|
if ((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && (__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK)
|
||||||
(__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && \
|
&& ((READ_BIT(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2)) {
|
||||||
((READ_BIT(RCC->CFGR2,RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2))
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_RCC_PLL2_MUL(PLL2Init->PLL2MUL));
|
assert_param(IS_RCC_PLL2_MUL(PLL2Init->PLL2MUL));
|
||||||
assert_param(IS_RCC_HSE_PREDIV2(PLL2Init->HSEPrediv2Value));
|
assert_param(IS_RCC_HSE_PREDIV2(PLL2Init->HSEPrediv2Value));
|
||||||
|
|
||||||
/* Prediv2 can be written only when the PLLI2S is disabled. */
|
/* Prediv2 can be written only when the PLLI2S is disabled. */
|
||||||
/* Return an error only if new value is different from the programmed value */
|
/* Return an error only if new value is different from the programmed value */
|
||||||
if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL3ON) && \
|
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON) && (__HAL_RCC_HSE_GET_PREDIV2() != PLL2Init->HSEPrediv2Value)) {
|
||||||
(__HAL_RCC_HSE_GET_PREDIV2() != PLL2Init->HSEPrediv2Value))
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -785,10 +691,8 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLL2(RCC_PLL2InitTypeDef *PLL2Init)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till PLL2 is disabled */
|
/* Wait till PLL2 is disabled */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -806,10 +710,8 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLL2(RCC_PLL2InitTypeDef *PLL2Init)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till PLL2 is ready */
|
/* Wait till PLL2 is ready */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) == RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) == RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -823,20 +725,15 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLL2(RCC_PLL2InitTypeDef *PLL2Init)
|
|||||||
* @note PLL2 is not disabled if used indirectly as system clock.
|
* @note PLL2 is not disabled if used indirectly as system clock.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_RCCEx_DisablePLL2(void)
|
HAL_StatusTypeDef HAL_RCCEx_DisablePLL2(void) {
|
||||||
{
|
|
||||||
uint32_t tickstart = 0U;
|
uint32_t tickstart = 0U;
|
||||||
|
|
||||||
/* This bit can not be cleared if the PLL2 clock is used indirectly as system
|
/* This bit can not be cleared if the PLL2 clock is used indirectly as system
|
||||||
clock (i.e. it is used as PLL clock entry that is used as system clock). */
|
clock (i.e. it is used as PLL clock entry that is used as system clock). */
|
||||||
if((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && \
|
if ((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && (__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK)
|
||||||
(__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && \
|
&& ((READ_BIT(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2)) {
|
||||||
((READ_BIT(RCC->CFGR2,RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2))
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Disable the main PLL2. */
|
/* Disable the main PLL2. */
|
||||||
__HAL_RCC_PLL2_DISABLE();
|
__HAL_RCC_PLL2_DISABLE();
|
||||||
|
|
||||||
@@ -844,10 +741,8 @@ HAL_StatusTypeDef HAL_RCCEx_DisablePLL2(void)
|
|||||||
tickstart = HAL_GetTick();
|
tickstart = HAL_GetTick();
|
||||||
|
|
||||||
/* Wait till PLL2 is disabled */
|
/* Wait till PLL2 is disabled */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET)
|
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET) {
|
||||||
{
|
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||||
if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
return HAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -876,4 +771,3 @@ HAL_StatusTypeDef HAL_RCCEx_DisablePLL2(void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -114,13 +114,11 @@
|
|||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
|
||||||
#if defined (STM32F100xB) || defined (STM32F100xE) || \
|
#if defined(STM32F100xB) || defined(STM32F100xE) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
|
|
||||||
defined (STM32F105xC) || defined (STM32F107xC)
|
|
||||||
/** @defgroup TIMEx_Private_Functions TIMEx Private Functions
|
/** @defgroup TIMEx_Private_Functions TIMEx Private Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState);
|
static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -134,7 +132,6 @@ static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t Cha
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup TIMEx_Exported_Functions_Group1 Timer Hall Sensor functions
|
/** @defgroup TIMEx_Exported_Functions_Group1 Timer Hall Sensor functions
|
||||||
* @brief Timer Hall Sensor functions
|
* @brief Timer Hall Sensor functions
|
||||||
*
|
*
|
||||||
@@ -162,13 +159,11 @@ static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t Cha
|
|||||||
* @param sConfig : TIM Hall Sensor configuration structure
|
* @param sConfig : TIM Hall Sensor configuration structure
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef* sConfig)
|
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig) {
|
||||||
{
|
|
||||||
TIM_OC_InitTypeDef OC_Config;
|
TIM_OC_InitTypeDef OC_Config;
|
||||||
|
|
||||||
/* Check the TIM handle allocation */
|
/* Check the TIM handle allocation */
|
||||||
if(htim == NULL)
|
if (htim == NULL) {
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,8 +175,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSen
|
|||||||
assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
|
assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
|
||||||
assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
|
assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
|
||||||
|
|
||||||
if(htim->State == HAL_TIM_STATE_RESET)
|
if (htim->State == HAL_TIM_STATE_RESET) {
|
||||||
{
|
|
||||||
/* Allocate lock resource and initialize it */
|
/* Allocate lock resource and initialize it */
|
||||||
htim->Lock = HAL_UNLOCKED;
|
htim->Lock = HAL_UNLOCKED;
|
||||||
|
|
||||||
@@ -190,7 +184,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSen
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set the TIM state */
|
/* Set the TIM state */
|
||||||
htim->State= HAL_TIM_STATE_BUSY;
|
htim->State = HAL_TIM_STATE_BUSY;
|
||||||
|
|
||||||
/* Configure the Time base in the Encoder Mode */
|
/* Configure the Time base in the Encoder Mode */
|
||||||
TIM_Base_SetConfig(htim->Instance, &htim->Init);
|
TIM_Base_SetConfig(htim->Instance, &htim->Init);
|
||||||
@@ -231,7 +225,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSen
|
|||||||
htim->Instance->CR2 |= TIM_TRGO_OC2REF;
|
htim->Instance->CR2 |= TIM_TRGO_OC2REF;
|
||||||
|
|
||||||
/* Initialize the TIM state*/
|
/* Initialize the TIM state*/
|
||||||
htim->State= HAL_TIM_STATE_READY;
|
htim->State = HAL_TIM_STATE_READY;
|
||||||
|
|
||||||
return HAL_OK;
|
return HAL_OK;
|
||||||
}
|
}
|
||||||
@@ -241,8 +235,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSen
|
|||||||
* @param htim : TIM Hall Sensor handle
|
* @param htim : TIM Hall Sensor handle
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim)
|
HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_INSTANCE(htim->Instance));
|
assert_param(IS_TIM_INSTANCE(htim->Instance));
|
||||||
|
|
||||||
@@ -268,8 +261,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim)
|
|||||||
* @param htim : TIM handle
|
* @param htim : TIM handle
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
|
__weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim) {
|
||||||
{
|
|
||||||
/* Prevent unused argument(s) compilation warning */
|
/* Prevent unused argument(s) compilation warning */
|
||||||
UNUSED(htim);
|
UNUSED(htim);
|
||||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||||
@@ -282,8 +274,7 @@ __weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
|
|||||||
* @param htim : TIM handle
|
* @param htim : TIM handle
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
|
__weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim) {
|
||||||
{
|
|
||||||
/* Prevent unused argument(s) compilation warning */
|
/* Prevent unused argument(s) compilation warning */
|
||||||
UNUSED(htim);
|
UNUSED(htim);
|
||||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||||
@@ -296,8 +287,7 @@ __weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
|
|||||||
* @param htim : TIM Hall Sensor handle
|
* @param htim : TIM Hall Sensor handle
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)
|
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
||||||
|
|
||||||
@@ -317,8 +307,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)
|
|||||||
* @param htim : TIM Hall Sensor handle
|
* @param htim : TIM Hall Sensor handle
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)
|
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
||||||
|
|
||||||
@@ -338,8 +327,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)
|
|||||||
* @param htim : TIM Hall Sensor handle
|
* @param htim : TIM Hall Sensor handle
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)
|
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
||||||
|
|
||||||
@@ -362,8 +350,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)
|
|||||||
* @param htim : TIM handle
|
* @param htim : TIM handle
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim)
|
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
||||||
|
|
||||||
@@ -388,23 +375,16 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim)
|
|||||||
* @param Length : The length of data to be transferred from TIM peripheral to memory.
|
* @param Length : The length of data to be transferred from TIM peripheral to memory.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
|
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
||||||
|
|
||||||
if((htim->State == HAL_TIM_STATE_BUSY))
|
if ((htim->State == HAL_TIM_STATE_BUSY)) {
|
||||||
{
|
|
||||||
return HAL_BUSY;
|
return HAL_BUSY;
|
||||||
}
|
} else if ((htim->State == HAL_TIM_STATE_READY)) {
|
||||||
else if((htim->State == HAL_TIM_STATE_READY))
|
if (((uint32_t)pData == 0U) && (Length > 0U)) {
|
||||||
{
|
|
||||||
if(((uint32_t)pData == 0U) && (Length > 0U))
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
htim->State = HAL_TIM_STATE_BUSY;
|
htim->State = HAL_TIM_STATE_BUSY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -415,7 +395,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32
|
|||||||
/* Set the DMA Input Capture 1 Callback */
|
/* Set the DMA Input Capture 1 Callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
|
htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
|
||||||
/* Set the DMA error callback */
|
/* Set the DMA error callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
|
htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError;
|
||||||
|
|
||||||
/* Enable the DMA channel for Capture 1*/
|
/* Enable the DMA channel for Capture 1*/
|
||||||
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length);
|
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length);
|
||||||
@@ -435,8 +415,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32
|
|||||||
* @param htim : TIM handle
|
* @param htim : TIM handle
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
|
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
||||||
|
|
||||||
@@ -444,7 +423,6 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
|
|||||||
(in the Hall Sensor Interface the 3 possible channels that are used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
|
(in the Hall Sensor Interface the 3 possible channels that are used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
|
||||||
TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
|
TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
|
||||||
|
|
||||||
|
|
||||||
/* Disable the capture compare Interrupts 1 event */
|
/* Disable the capture compare Interrupts 1 event */
|
||||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
|
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
|
||||||
|
|
||||||
@@ -459,9 +437,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
|
|||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined (STM32F100xB) || defined (STM32F100xE) || \
|
#if defined(STM32F100xB) || defined(STM32F100xE) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
|
|
||||||
defined (STM32F105xC) || defined (STM32F107xC)
|
|
||||||
|
|
||||||
/** @defgroup TIMEx_Exported_Functions_Group2 Timer Complementary Output Compare functions
|
/** @defgroup TIMEx_Exported_Functions_Group2 Timer Complementary Output Compare functions
|
||||||
* @brief Timer Complementary Output Compare functions
|
* @brief Timer Complementary Output Compare functions
|
||||||
@@ -494,8 +470,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
|
|||||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
|
HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||||
|
|
||||||
@@ -523,8 +498,7 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
|
|||||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
|
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||||
|
|
||||||
@@ -552,33 +526,25 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
|
|||||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
|
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||||
|
|
||||||
switch (Channel)
|
switch (Channel) {
|
||||||
{
|
case TIM_CHANNEL_1: {
|
||||||
case TIM_CHANNEL_1:
|
|
||||||
{
|
|
||||||
/* Enable the TIM Output Compare interrupt */
|
/* Enable the TIM Output Compare interrupt */
|
||||||
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
|
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_2:
|
case TIM_CHANNEL_2: {
|
||||||
{
|
|
||||||
/* Enable the TIM Output Compare interrupt */
|
/* Enable the TIM Output Compare interrupt */
|
||||||
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
|
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_3:
|
case TIM_CHANNEL_3: {
|
||||||
{
|
|
||||||
/* Enable the TIM Output Compare interrupt */
|
/* Enable the TIM Output Compare interrupt */
|
||||||
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
|
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -611,35 +577,27 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Chann
|
|||||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
|
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||||
{
|
|
||||||
uint32_t tmpccer = 0U;
|
uint32_t tmpccer = 0U;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||||
|
|
||||||
switch (Channel)
|
switch (Channel) {
|
||||||
{
|
case TIM_CHANNEL_1: {
|
||||||
case TIM_CHANNEL_1:
|
|
||||||
{
|
|
||||||
/* Disable the TIM Output Compare interrupt */
|
/* Disable the TIM Output Compare interrupt */
|
||||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
|
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_2:
|
case TIM_CHANNEL_2: {
|
||||||
{
|
|
||||||
/* Disable the TIM Output Compare interrupt */
|
/* Disable the TIM Output Compare interrupt */
|
||||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
|
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_3:
|
case TIM_CHANNEL_3: {
|
||||||
{
|
|
||||||
/* Disable the TIM Output Compare interrupt */
|
/* Disable the TIM Output Compare interrupt */
|
||||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
|
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -650,8 +608,7 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channe
|
|||||||
|
|
||||||
/* Disable the TIM Break interrupt (only if no more channel is active) */
|
/* Disable the TIM Break interrupt (only if no more channel is active) */
|
||||||
tmpccer = htim->Instance->CCER;
|
tmpccer = htim->Instance->CCER;
|
||||||
if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
|
if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET) {
|
||||||
{
|
|
||||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
|
__HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,75 +635,61 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channe
|
|||||||
* @param Length : The length of data to be transferred from memory to TIM peripheral
|
* @param Length : The length of data to be transferred from memory to TIM peripheral
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
|
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||||
|
|
||||||
if((htim->State == HAL_TIM_STATE_BUSY))
|
if ((htim->State == HAL_TIM_STATE_BUSY)) {
|
||||||
{
|
|
||||||
return HAL_BUSY;
|
return HAL_BUSY;
|
||||||
}
|
} else if ((htim->State == HAL_TIM_STATE_READY)) {
|
||||||
else if((htim->State == HAL_TIM_STATE_READY))
|
if (((uint32_t)pData == 0U) && (Length > 0U)) {
|
||||||
{
|
|
||||||
if(((uint32_t)pData == 0U) && (Length > 0U))
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
htim->State = HAL_TIM_STATE_BUSY;
|
htim->State = HAL_TIM_STATE_BUSY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (Channel)
|
switch (Channel) {
|
||||||
{
|
case TIM_CHANNEL_1: {
|
||||||
case TIM_CHANNEL_1:
|
|
||||||
{
|
|
||||||
/* Set the DMA Period elapsed callback */
|
/* Set the DMA Period elapsed callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
||||||
|
|
||||||
/* Set the DMA error callback */
|
/* Set the DMA error callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
|
htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError;
|
||||||
|
|
||||||
/* Enable the DMA channel */
|
/* Enable the DMA channel */
|
||||||
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
|
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
|
||||||
|
|
||||||
/* Enable the TIM Output Compare DMA request */
|
/* Enable the TIM Output Compare DMA request */
|
||||||
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
|
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_2:
|
case TIM_CHANNEL_2: {
|
||||||
{
|
|
||||||
/* Set the DMA Period elapsed callback */
|
/* Set the DMA Period elapsed callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
||||||
|
|
||||||
/* Set the DMA error callback */
|
/* Set the DMA error callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
|
htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError;
|
||||||
|
|
||||||
/* Enable the DMA channel */
|
/* Enable the DMA channel */
|
||||||
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
|
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
|
||||||
|
|
||||||
/* Enable the TIM Output Compare DMA request */
|
/* Enable the TIM Output Compare DMA request */
|
||||||
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
|
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_3:
|
case TIM_CHANNEL_3: {
|
||||||
{
|
|
||||||
/* Set the DMA Period elapsed callback */
|
/* Set the DMA Period elapsed callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
||||||
|
|
||||||
/* Set the DMA error callback */
|
/* Set the DMA error callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
|
htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError;
|
||||||
|
|
||||||
/* Enable the DMA channel */
|
/* Enable the DMA channel */
|
||||||
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
|
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length);
|
||||||
|
|
||||||
/* Enable the TIM Output Compare DMA request */
|
/* Enable the TIM Output Compare DMA request */
|
||||||
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
|
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -776,33 +719,25 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Chan
|
|||||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
|
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||||
|
|
||||||
switch (Channel)
|
switch (Channel) {
|
||||||
{
|
case TIM_CHANNEL_1: {
|
||||||
case TIM_CHANNEL_1:
|
|
||||||
{
|
|
||||||
/* Disable the TIM Output Compare DMA request */
|
/* Disable the TIM Output Compare DMA request */
|
||||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
|
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_2:
|
case TIM_CHANNEL_2: {
|
||||||
{
|
|
||||||
/* Disable the TIM Output Compare DMA request */
|
/* Disable the TIM Output Compare DMA request */
|
||||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
|
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_3:
|
case TIM_CHANNEL_3: {
|
||||||
{
|
|
||||||
/* Disable the TIM Output Compare DMA request */
|
/* Disable the TIM Output Compare DMA request */
|
||||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
|
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -868,8 +803,7 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Chann
|
|||||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
|
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||||
|
|
||||||
@@ -896,8 +830,7 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel
|
|||||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
|
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||||
|
|
||||||
@@ -925,33 +858,25 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
|
|||||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
|
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||||
|
|
||||||
switch (Channel)
|
switch (Channel) {
|
||||||
{
|
case TIM_CHANNEL_1: {
|
||||||
case TIM_CHANNEL_1:
|
|
||||||
{
|
|
||||||
/* Enable the TIM Capture/Compare 1 interrupt */
|
/* Enable the TIM Capture/Compare 1 interrupt */
|
||||||
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
|
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_2:
|
case TIM_CHANNEL_2: {
|
||||||
{
|
|
||||||
/* Enable the TIM Capture/Compare 2 interrupt */
|
/* Enable the TIM Capture/Compare 2 interrupt */
|
||||||
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
|
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_3:
|
case TIM_CHANNEL_3: {
|
||||||
{
|
|
||||||
/* Enable the TIM Capture/Compare 3 interrupt */
|
/* Enable the TIM Capture/Compare 3 interrupt */
|
||||||
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
|
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -984,35 +909,27 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Chan
|
|||||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
|
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||||
{
|
|
||||||
uint32_t tmpccer = 0U;
|
uint32_t tmpccer = 0U;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||||
|
|
||||||
switch (Channel)
|
switch (Channel) {
|
||||||
{
|
case TIM_CHANNEL_1: {
|
||||||
case TIM_CHANNEL_1:
|
|
||||||
{
|
|
||||||
/* Disable the TIM Capture/Compare 1 interrupt */
|
/* Disable the TIM Capture/Compare 1 interrupt */
|
||||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
|
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_2:
|
case TIM_CHANNEL_2: {
|
||||||
{
|
|
||||||
/* Disable the TIM Capture/Compare 2 interrupt */
|
/* Disable the TIM Capture/Compare 2 interrupt */
|
||||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
|
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_3:
|
case TIM_CHANNEL_3: {
|
||||||
{
|
|
||||||
/* Disable the TIM Capture/Compare 3 interrupt */
|
/* Disable the TIM Capture/Compare 3 interrupt */
|
||||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
|
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -1023,8 +940,7 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Chann
|
|||||||
|
|
||||||
/* Disable the TIM Break interrupt (only if no more channel is active) */
|
/* Disable the TIM Break interrupt (only if no more channel is active) */
|
||||||
tmpccer = htim->Instance->CCER;
|
tmpccer = htim->Instance->CCER;
|
||||||
if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
|
if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET) {
|
||||||
{
|
|
||||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
|
__HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1051,75 +967,61 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Chann
|
|||||||
* @param Length : The length of data to be transferred from memory to TIM peripheral
|
* @param Length : The length of data to be transferred from memory to TIM peripheral
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
|
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||||
|
|
||||||
if((htim->State == HAL_TIM_STATE_BUSY))
|
if ((htim->State == HAL_TIM_STATE_BUSY)) {
|
||||||
{
|
|
||||||
return HAL_BUSY;
|
return HAL_BUSY;
|
||||||
}
|
} else if ((htim->State == HAL_TIM_STATE_READY)) {
|
||||||
else if((htim->State == HAL_TIM_STATE_READY))
|
if (((uint32_t)pData == 0U) && (Length > 0U)) {
|
||||||
{
|
|
||||||
if(((uint32_t)pData == 0U) && (Length > 0U))
|
|
||||||
{
|
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
htim->State = HAL_TIM_STATE_BUSY;
|
htim->State = HAL_TIM_STATE_BUSY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (Channel)
|
switch (Channel) {
|
||||||
{
|
case TIM_CHANNEL_1: {
|
||||||
case TIM_CHANNEL_1:
|
|
||||||
{
|
|
||||||
/* Set the DMA Period elapsed callback */
|
/* Set the DMA Period elapsed callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
||||||
|
|
||||||
/* Set the DMA error callback */
|
/* Set the DMA error callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
|
htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError;
|
||||||
|
|
||||||
/* Enable the DMA channel */
|
/* Enable the DMA channel */
|
||||||
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
|
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
|
||||||
|
|
||||||
/* Enable the TIM Capture/Compare 1 DMA request */
|
/* Enable the TIM Capture/Compare 1 DMA request */
|
||||||
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
|
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_2:
|
case TIM_CHANNEL_2: {
|
||||||
{
|
|
||||||
/* Set the DMA Period elapsed callback */
|
/* Set the DMA Period elapsed callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
||||||
|
|
||||||
/* Set the DMA error callback */
|
/* Set the DMA error callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
|
htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError;
|
||||||
|
|
||||||
/* Enable the DMA channel */
|
/* Enable the DMA channel */
|
||||||
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
|
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
|
||||||
|
|
||||||
/* Enable the TIM Capture/Compare 2 DMA request */
|
/* Enable the TIM Capture/Compare 2 DMA request */
|
||||||
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
|
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_3:
|
case TIM_CHANNEL_3: {
|
||||||
{
|
|
||||||
/* Set the DMA Period elapsed callback */
|
/* Set the DMA Period elapsed callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
||||||
|
|
||||||
/* Set the DMA error callback */
|
/* Set the DMA error callback */
|
||||||
htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
|
htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError;
|
||||||
|
|
||||||
/* Enable the DMA channel */
|
/* Enable the DMA channel */
|
||||||
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
|
HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length);
|
||||||
|
|
||||||
/* Enable the TIM Capture/Compare 3 DMA request */
|
/* Enable the TIM Capture/Compare 3 DMA request */
|
||||||
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
|
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -1149,33 +1051,25 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Cha
|
|||||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
|
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||||
|
|
||||||
switch (Channel)
|
switch (Channel) {
|
||||||
{
|
case TIM_CHANNEL_1: {
|
||||||
case TIM_CHANNEL_1:
|
|
||||||
{
|
|
||||||
/* Disable the TIM Capture/Compare 1 DMA request */
|
/* Disable the TIM Capture/Compare 1 DMA request */
|
||||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
|
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_2:
|
case TIM_CHANNEL_2: {
|
||||||
{
|
|
||||||
/* Disable the TIM Capture/Compare 2 DMA request */
|
/* Disable the TIM Capture/Compare 2 DMA request */
|
||||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
|
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TIM_CHANNEL_3:
|
case TIM_CHANNEL_3: {
|
||||||
{
|
|
||||||
/* Disable the TIM Capture/Compare 3 DMA request */
|
/* Disable the TIM Capture/Compare 3 DMA request */
|
||||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
|
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -1229,8 +1123,7 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Chan
|
|||||||
* @arg TIM_CHANNEL_2: TIM Channel 2 selected
|
* @arg TIM_CHANNEL_2: TIM Channel 2 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
|
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
|
||||||
|
|
||||||
@@ -1254,8 +1147,7 @@ HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t Ou
|
|||||||
* @arg TIM_CHANNEL_2: TIM Channel 2 selected
|
* @arg TIM_CHANNEL_2: TIM Channel 2 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
|
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel) {
|
||||||
{
|
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
|
||||||
@@ -1283,8 +1175,7 @@ HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t Out
|
|||||||
* @arg TIM_CHANNEL_2: TIM Channel 2 selected
|
* @arg TIM_CHANNEL_2: TIM Channel 2 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
|
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
|
||||||
|
|
||||||
@@ -1314,8 +1205,7 @@ HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t
|
|||||||
* @arg TIM_CHANNEL_2: TIM Channel 2 selected
|
* @arg TIM_CHANNEL_2: TIM Channel 2 selected
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
|
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
|
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
|
||||||
|
|
||||||
@@ -1363,9 +1253,7 @@ HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined (STM32F100xB) || defined (STM32F100xE) || \
|
#if defined(STM32F100xB) || defined(STM32F100xE) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
|
|
||||||
defined (STM32F105xC) || defined (STM32F107xC)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Configure the TIM commutation event sequence.
|
* @brief Configure the TIM commutation event sequence.
|
||||||
@@ -1389,17 +1277,14 @@ HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t
|
|||||||
* @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
|
* @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
|
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
|
assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
|
||||||
assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
|
assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
|
||||||
|
|
||||||
__HAL_LOCK(htim);
|
__HAL_LOCK(htim);
|
||||||
|
|
||||||
if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
|
if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) || (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3)) {
|
||||||
(InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
|
|
||||||
{
|
|
||||||
/* Select the Input trigger */
|
/* Select the Input trigger */
|
||||||
htim->Instance->SMCR &= ~TIM_SMCR_TS;
|
htim->Instance->SMCR &= ~TIM_SMCR_TS;
|
||||||
htim->Instance->SMCR |= InputTrigger;
|
htim->Instance->SMCR |= InputTrigger;
|
||||||
@@ -1438,17 +1323,14 @@ HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint
|
|||||||
* @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
|
* @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
|
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
|
assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
|
||||||
assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
|
assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
|
||||||
|
|
||||||
__HAL_LOCK(htim);
|
__HAL_LOCK(htim);
|
||||||
|
|
||||||
if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
|
if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) || (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3)) {
|
||||||
(InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
|
|
||||||
{
|
|
||||||
/* Select the Input trigger */
|
/* Select the Input trigger */
|
||||||
htim->Instance->SMCR &= ~TIM_SMCR_TS;
|
htim->Instance->SMCR &= ~TIM_SMCR_TS;
|
||||||
htim->Instance->SMCR |= InputTrigger;
|
htim->Instance->SMCR |= InputTrigger;
|
||||||
@@ -1491,17 +1373,14 @@ HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, u
|
|||||||
* @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
|
* @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
|
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
|
assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
|
||||||
assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
|
assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
|
||||||
|
|
||||||
__HAL_LOCK(htim);
|
__HAL_LOCK(htim);
|
||||||
|
|
||||||
if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
|
if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) || (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3)) {
|
||||||
(InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
|
|
||||||
{
|
|
||||||
/* Select the Input trigger */
|
/* Select the Input trigger */
|
||||||
htim->Instance->SMCR &= ~TIM_SMCR_TS;
|
htim->Instance->SMCR &= ~TIM_SMCR_TS;
|
||||||
htim->Instance->SMCR |= InputTrigger;
|
htim->Instance->SMCR |= InputTrigger;
|
||||||
@@ -1535,9 +1414,7 @@ HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef *htim,
|
|||||||
* contains the BDTR Register configuration information for the TIM peripheral.
|
* contains the BDTR Register configuration information for the TIM peripheral.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
|
HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim, TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig) {
|
||||||
TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig)
|
|
||||||
{
|
|
||||||
uint32_t tmpbdtr = 0U;
|
uint32_t tmpbdtr = 0U;
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
@@ -1586,8 +1463,7 @@ HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
|
|||||||
* mode.
|
* mode.
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef * sMasterConfig)
|
HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef *sMasterConfig) {
|
||||||
{
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance));
|
assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance));
|
||||||
assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
|
assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
|
||||||
@@ -1639,8 +1515,7 @@ HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
|
|||||||
* @param htim : TIM handle
|
* @param htim : TIM handle
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim)
|
__weak void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim) {
|
||||||
{
|
|
||||||
/* Prevent unused argument(s) compilation warning */
|
/* Prevent unused argument(s) compilation warning */
|
||||||
UNUSED(htim);
|
UNUSED(htim);
|
||||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||||
@@ -1653,8 +1528,7 @@ __weak void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim)
|
|||||||
* @param htim : TIM handle
|
* @param htim : TIM handle
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
__weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
|
__weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim) {
|
||||||
{
|
|
||||||
/* Prevent unused argument(s) compilation warning */
|
/* Prevent unused argument(s) compilation warning */
|
||||||
UNUSED(htim);
|
UNUSED(htim);
|
||||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||||
@@ -1667,11 +1541,10 @@ __weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
|
|||||||
* @param hdma : pointer to DMA handle.
|
* @param hdma : pointer to DMA handle.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
|
void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma) {
|
||||||
{
|
TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
|
||||||
TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
|
||||||
|
|
||||||
htim->State= HAL_TIM_STATE_READY;
|
htim->State = HAL_TIM_STATE_READY;
|
||||||
|
|
||||||
HAL_TIMEx_CommutationCallback(htim);
|
HAL_TIMEx_CommutationCallback(htim);
|
||||||
}
|
}
|
||||||
@@ -1680,9 +1553,7 @@ void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
|
|||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined (STM32F100xB) || defined (STM32F100xE) || \
|
#if defined(STM32F100xB) || defined(STM32F100xE) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
|
|
||||||
defined (STM32F105xC) || defined (STM32F107xC)
|
|
||||||
|
|
||||||
/** @defgroup TIMEx_Exported_Functions_Group7 Extension Peripheral State functions
|
/** @defgroup TIMEx_Exported_Functions_Group7 Extension Peripheral State functions
|
||||||
* @brief Extension Peripheral State functions
|
* @brief Extension Peripheral State functions
|
||||||
@@ -1704,10 +1575,7 @@ void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
|
|||||||
* @param htim : TIM Hall Sensor handle
|
* @param htim : TIM Hall Sensor handle
|
||||||
* @retval HAL state
|
* @retval HAL state
|
||||||
*/
|
*/
|
||||||
HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
|
HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim) { return htim->State; }
|
||||||
{
|
|
||||||
return htim->State;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -1720,9 +1588,7 @@ HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
|
|||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined (STM32F100xB) || defined (STM32F100xE) || \
|
#if defined(STM32F100xB) || defined(STM32F100xE) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
|
|
||||||
defined (STM32F105xC) || defined (STM32F107xC)
|
|
||||||
|
|
||||||
/** @addtogroup TIMEx_Private_Functions
|
/** @addtogroup TIMEx_Private_Functions
|
||||||
* @{
|
* @{
|
||||||
@@ -1740,8 +1606,7 @@ HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
|
|||||||
* This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable.
|
* This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState)
|
static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState) {
|
||||||
{
|
|
||||||
uint32_t tmp = 0U;
|
uint32_t tmp = 0U;
|
||||||
|
|
||||||
tmp = TIM_CCER_CC1NE << Channel;
|
tmp = TIM_CCER_CC1NE << Channel;
|
||||||
|
|||||||
@@ -5,23 +5,22 @@
|
|||||||
* Author: Ralim
|
* Author: Ralim
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "BSP_Flash.h"
|
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "string.h"
|
#include "BSP_Flash.h"
|
||||||
#include "stm32f1xx_hal.h"
|
#include "stm32f1xx_hal.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
static uint16_t settings_page[512] __attribute__ ((section (".settings_page")));
|
static uint16_t settings_page[512] __attribute__((section(".settings_page")));
|
||||||
|
|
||||||
uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
|
uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
|
||||||
FLASH_EraseInitTypeDef pEraseInit;
|
FLASH_EraseInitTypeDef pEraseInit;
|
||||||
pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||||
pEraseInit.Banks = FLASH_BANK_1;
|
pEraseInit.Banks = FLASH_BANK_1;
|
||||||
pEraseInit.NbPages = 1;
|
pEraseInit.NbPages = 1;
|
||||||
pEraseInit.PageAddress = (uint32_t) settings_page;
|
pEraseInit.PageAddress = (uint32_t)settings_page;
|
||||||
uint32_t failingAddress = 0;
|
uint32_t failingAddress = 0;
|
||||||
resetWatchdog();
|
resetWatchdog();
|
||||||
__HAL_FLASH_CLEAR_FLAG(
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);
|
||||||
FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);
|
|
||||||
HAL_FLASH_Unlock();
|
HAL_FLASH_Unlock();
|
||||||
HAL_Delay(1);
|
HAL_Delay(1);
|
||||||
resetWatchdog();
|
resetWatchdog();
|
||||||
@@ -29,18 +28,14 @@ uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
|
|||||||
//^ Erase the page of flash (1024 bytes on this stm32)
|
//^ Erase the page of flash (1024 bytes on this stm32)
|
||||||
// erased the chunk
|
// erased the chunk
|
||||||
// now we program it
|
// now we program it
|
||||||
uint16_t *data = (uint16_t*) buffer;
|
uint16_t *data = (uint16_t *)buffer;
|
||||||
HAL_FLASH_Unlock();
|
HAL_FLASH_Unlock();
|
||||||
for (uint8_t i = 0; i < (length / 2); i++) {
|
for (uint8_t i = 0; i < (length / 2); i++) {
|
||||||
resetWatchdog();
|
resetWatchdog();
|
||||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,
|
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, (uint32_t)&settings_page[i], data[i]);
|
||||||
(uint32_t) &settings_page[i], data[i]);
|
|
||||||
}
|
}
|
||||||
HAL_FLASH_Lock();
|
HAL_FLASH_Lock();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void flash_read_buffer(uint8_t *buffer, const uint16_t length) {
|
void flash_read_buffer(uint8_t *buffer, const uint16_t length) { memcpy(buffer, settings_page, length); }
|
||||||
|
|
||||||
memcpy(buffer, settings_page, length);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -17,10 +17,10 @@
|
|||||||
#include "Model_Config.h"
|
#include "Model_Config.h"
|
||||||
#ifdef POW_PD
|
#ifdef POW_PD
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "fusb302b.h"
|
|
||||||
#include "I2CBB.hpp"
|
#include "I2CBB.hpp"
|
||||||
#include <pd.h>
|
#include "fusb302b.h"
|
||||||
#include "int_n.h"
|
#include "int_n.h"
|
||||||
|
#include <pd.h>
|
||||||
/*
|
/*
|
||||||
* Read a single byte from the FUSB302B
|
* Read a single byte from the FUSB302B
|
||||||
*
|
*
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
*/
|
*/
|
||||||
static uint8_t fusb_read_byte(uint8_t addr) {
|
static uint8_t fusb_read_byte(uint8_t addr) {
|
||||||
uint8_t data[1];
|
uint8_t data[1];
|
||||||
if (!I2CBB::Mem_Read(FUSB302B_ADDR, addr, (uint8_t*) data, 1)) {
|
if (!I2CBB::Mem_Read(FUSB302B_ADDR, addr, (uint8_t *)data, 1)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return data[0];
|
return data[0];
|
||||||
@@ -45,9 +45,7 @@ static uint8_t fusb_read_byte(uint8_t addr) {
|
|||||||
* size: The number of bytes to read
|
* size: The number of bytes to read
|
||||||
* buf: The buffer into which data will be read
|
* buf: The buffer into which data will be read
|
||||||
*/
|
*/
|
||||||
static bool fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) {
|
static bool fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) { return I2CBB::Mem_Read(FUSB302B_ADDR, addr, buf, size); }
|
||||||
return I2CBB::Mem_Read(FUSB302B_ADDR, addr, buf, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write a single byte to the FUSB302B
|
* Write a single byte to the FUSB302B
|
||||||
@@ -56,9 +54,7 @@ static bool fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) {
|
|||||||
* addr: The memory address to which we will write
|
* addr: The memory address to which we will write
|
||||||
* byte: The value to write
|
* byte: The value to write
|
||||||
*/
|
*/
|
||||||
static bool fusb_write_byte(uint8_t addr, uint8_t byte) {
|
static bool fusb_write_byte(uint8_t addr, uint8_t byte) { return I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t *)&byte, 1); }
|
||||||
return I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) &byte, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write multiple bytes to the FUSB302B
|
* Write multiple bytes to the FUSB302B
|
||||||
@@ -68,26 +64,15 @@ static bool fusb_write_byte(uint8_t addr, uint8_t byte) {
|
|||||||
* size: The number of bytes to write
|
* size: The number of bytes to write
|
||||||
* buf: The buffer to write
|
* buf: The buffer to write
|
||||||
*/
|
*/
|
||||||
static bool fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) {
|
static bool fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) { return I2CBB::Mem_Write(FUSB302B_ADDR, addr, buf, size); }
|
||||||
return I2CBB::Mem_Write(FUSB302B_ADDR, addr, buf, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fusb_send_message(const union pd_msg *msg) {
|
void fusb_send_message(const union pd_msg *msg) {
|
||||||
if (!I2CBB::lock2()) {
|
if (!I2CBB::lock2()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Token sequences for the FUSB302B */
|
/* Token sequences for the FUSB302B */
|
||||||
static uint8_t sop_seq[5] = {
|
static uint8_t sop_seq[5] = {FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP2, FUSB_FIFO_TX_PACKSYM};
|
||||||
FUSB_FIFO_TX_SOP1,
|
static const uint8_t eop_seq[4] = {FUSB_FIFO_TX_JAM_CRC, FUSB_FIFO_TX_EOP, FUSB_FIFO_TX_TXOFF, FUSB_FIFO_TX_TXON};
|
||||||
FUSB_FIFO_TX_SOP1,
|
|
||||||
FUSB_FIFO_TX_SOP1,
|
|
||||||
FUSB_FIFO_TX_SOP2,
|
|
||||||
FUSB_FIFO_TX_PACKSYM };
|
|
||||||
static const uint8_t eop_seq[4] = {
|
|
||||||
FUSB_FIFO_TX_JAM_CRC,
|
|
||||||
FUSB_FIFO_TX_EOP,
|
|
||||||
FUSB_FIFO_TX_TXOFF,
|
|
||||||
FUSB_FIFO_TX_TXON };
|
|
||||||
|
|
||||||
/* Take the I2C2 mutex now so there can't be a race condition on sop_seq */
|
/* Take the I2C2 mutex now so there can't be a race condition on sop_seq */
|
||||||
/* Get the length of the message: a two-octet header plus NUMOBJ four-octet
|
/* Get the length of the message: a two-octet header plus NUMOBJ four-octet
|
||||||
@@ -98,12 +83,11 @@ void fusb_send_message(const union pd_msg *msg) {
|
|||||||
sop_seq[4] = FUSB_FIFO_TX_PACKSYM | msg_len;
|
sop_seq[4] = FUSB_FIFO_TX_PACKSYM | msg_len;
|
||||||
|
|
||||||
/* Write all three parts of the message to the TX FIFO */
|
/* Write all three parts of the message to the TX FIFO */
|
||||||
fusb_write_buf( FUSB_FIFOS, 5, sop_seq);
|
fusb_write_buf(FUSB_FIFOS, 5, sop_seq);
|
||||||
fusb_write_buf( FUSB_FIFOS, msg_len, msg->bytes);
|
fusb_write_buf(FUSB_FIFOS, msg_len, msg->bytes);
|
||||||
fusb_write_buf( FUSB_FIFOS, 4, eop_seq);
|
fusb_write_buf(FUSB_FIFOS, 4, eop_seq);
|
||||||
|
|
||||||
I2CBB::unlock2();
|
I2CBB::unlock2();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t fusb_read_message(union pd_msg *msg) {
|
uint8_t fusb_read_message(union pd_msg *msg) {
|
||||||
@@ -115,17 +99,17 @@ uint8_t fusb_read_message(union pd_msg *msg) {
|
|||||||
|
|
||||||
// Read the header. If its not a SOP we dont actually want it at all
|
// Read the header. If its not a SOP we dont actually want it at all
|
||||||
// But on some revisions of the fusb if you dont both pick them up and read them out of the fifo, it gets stuck
|
// But on some revisions of the fusb if you dont both pick them up and read them out of the fifo, it gets stuck
|
||||||
fusb_read_byte( FUSB_FIFOS);
|
fusb_read_byte(FUSB_FIFOS);
|
||||||
/* Read the message header into msg */
|
/* Read the message header into msg */
|
||||||
fusb_read_buf( FUSB_FIFOS, 2, msg->bytes);
|
fusb_read_buf(FUSB_FIFOS, 2, msg->bytes);
|
||||||
/* Get the number of data objects */
|
/* Get the number of data objects */
|
||||||
numobj = PD_NUMOBJ_GET(msg);
|
numobj = PD_NUMOBJ_GET(msg);
|
||||||
/* If there is at least one data object, read the data objects */
|
/* If there is at least one data object, read the data objects */
|
||||||
if (numobj > 0) {
|
if (numobj > 0) {
|
||||||
fusb_read_buf( FUSB_FIFOS, numobj * 4, msg->bytes + 2);
|
fusb_read_buf(FUSB_FIFOS, numobj * 4, msg->bytes + 2);
|
||||||
}
|
}
|
||||||
/* Throw the CRC32 in the garbage, since the PHY already checked it. */
|
/* Throw the CRC32 in the garbage, since the PHY already checked it. */
|
||||||
fusb_read_buf( FUSB_FIFOS, 4, garbage);
|
fusb_read_buf(FUSB_FIFOS, 4, garbage);
|
||||||
|
|
||||||
I2CBB::unlock2();
|
I2CBB::unlock2();
|
||||||
return 0;
|
return 0;
|
||||||
@@ -137,7 +121,7 @@ void fusb_send_hardrst() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Send a hard reset */
|
/* Send a hard reset */
|
||||||
fusb_write_byte( FUSB_CONTROL3, 0x07 | FUSB_CONTROL3_SEND_HARD_RESET);
|
fusb_write_byte(FUSB_CONTROL3, 0x07 | FUSB_CONTROL3_SEND_HARD_RESET);
|
||||||
|
|
||||||
I2CBB::unlock2();
|
I2CBB::unlock2();
|
||||||
}
|
}
|
||||||
@@ -148,47 +132,46 @@ bool fusb_setup() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/* Fully reset the FUSB302B */
|
/* Fully reset the FUSB302B */
|
||||||
// fusb_write_byte( FUSB_RESET, FUSB_RESET_SW_RES);
|
// fusb_write_byte( FUSB_RESET, FUSB_RESET_SW_RES);
|
||||||
// osDelay(2);
|
// osDelay(2);
|
||||||
if (!fusb_read_id()) {
|
if (!fusb_read_id()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Turn on all power */
|
/* Turn on all power */
|
||||||
fusb_write_byte( FUSB_POWER, 0x0F);
|
fusb_write_byte(FUSB_POWER, 0x0F);
|
||||||
|
|
||||||
/* Set interrupt masks */
|
/* Set interrupt masks */
|
||||||
//Setting to 0 so interrupts are allowed
|
// Setting to 0 so interrupts are allowed
|
||||||
fusb_write_byte( FUSB_MASK1, 0x00);
|
fusb_write_byte(FUSB_MASK1, 0x00);
|
||||||
fusb_write_byte( FUSB_MASKA, 0x00);
|
fusb_write_byte(FUSB_MASKA, 0x00);
|
||||||
fusb_write_byte( FUSB_MASKB, 0x00);
|
fusb_write_byte(FUSB_MASKB, 0x00);
|
||||||
fusb_write_byte( FUSB_CONTROL0, 0b11 << 2);
|
fusb_write_byte(FUSB_CONTROL0, 0b11 << 2);
|
||||||
|
|
||||||
/* Enable automatic retransmission */
|
/* Enable automatic retransmission */
|
||||||
fusb_write_byte( FUSB_CONTROL3, 0x07);
|
fusb_write_byte(FUSB_CONTROL3, 0x07);
|
||||||
//set defaults
|
// set defaults
|
||||||
fusb_write_byte( FUSB_CONTROL2, 0x00);
|
fusb_write_byte(FUSB_CONTROL2, 0x00);
|
||||||
/* Flush the RX buffer */
|
/* Flush the RX buffer */
|
||||||
fusb_write_byte( FUSB_CONTROL1,
|
fusb_write_byte(FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH);
|
||||||
FUSB_CONTROL1_RX_FLUSH);
|
|
||||||
|
|
||||||
/* Measure CC1 */
|
/* Measure CC1 */
|
||||||
fusb_write_byte( FUSB_SWITCHES0, 0x07);
|
fusb_write_byte(FUSB_SWITCHES0, 0x07);
|
||||||
osDelay(10);
|
osDelay(10);
|
||||||
uint8_t cc1 = fusb_read_byte( FUSB_STATUS0) & FUSB_STATUS0_BC_LVL;
|
uint8_t cc1 = fusb_read_byte(FUSB_STATUS0) & FUSB_STATUS0_BC_LVL;
|
||||||
|
|
||||||
/* Measure CC2 */
|
/* Measure CC2 */
|
||||||
fusb_write_byte( FUSB_SWITCHES0, 0x0B);
|
fusb_write_byte(FUSB_SWITCHES0, 0x0B);
|
||||||
osDelay(10);
|
osDelay(10);
|
||||||
uint8_t cc2 = fusb_read_byte( FUSB_STATUS0) & FUSB_STATUS0_BC_LVL;
|
uint8_t cc2 = fusb_read_byte(FUSB_STATUS0) & FUSB_STATUS0_BC_LVL;
|
||||||
|
|
||||||
/* Select the correct CC line for BMC signaling; also enable AUTO_CRC */
|
/* Select the correct CC line for BMC signaling; also enable AUTO_CRC */
|
||||||
if (cc1 > cc2) {
|
if (cc1 > cc2) {
|
||||||
fusb_write_byte( FUSB_SWITCHES1, 0x25);
|
fusb_write_byte(FUSB_SWITCHES1, 0x25);
|
||||||
fusb_write_byte( FUSB_SWITCHES0, 0x07);
|
fusb_write_byte(FUSB_SWITCHES0, 0x07);
|
||||||
} else {
|
} else {
|
||||||
fusb_write_byte( FUSB_SWITCHES1, 0x26);
|
fusb_write_byte(FUSB_SWITCHES1, 0x26);
|
||||||
fusb_write_byte( FUSB_SWITCHES0, 0x0B);
|
fusb_write_byte(FUSB_SWITCHES0, 0x0B);
|
||||||
}
|
}
|
||||||
I2CBB::unlock2();
|
I2CBB::unlock2();
|
||||||
fusb_reset();
|
fusb_reset();
|
||||||
@@ -211,11 +194,10 @@ void fusb_get_status(union fusb_status *status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read the interrupt and status flags into status */
|
/* Read the interrupt and status flags into status */
|
||||||
fusb_read_buf( FUSB_STATUS0A, 7, status->bytes);
|
fusb_read_buf(FUSB_STATUS0A, 7, status->bytes);
|
||||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||||
I2CBB::unlock2();
|
I2CBB::unlock2();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum fusb_typec_current fusb_get_typec_current() {
|
enum fusb_typec_current fusb_get_typec_current() {
|
||||||
@@ -225,8 +207,7 @@ enum fusb_typec_current fusb_get_typec_current() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Read the BC_LVL into a variable */
|
/* Read the BC_LVL into a variable */
|
||||||
enum fusb_typec_current bc_lvl = (enum fusb_typec_current) (fusb_read_byte(
|
enum fusb_typec_current bc_lvl = (enum fusb_typec_current)(fusb_read_byte(FUSB_STATUS0) & FUSB_STATUS0_BC_LVL);
|
||||||
FUSB_STATUS0) & FUSB_STATUS0_BC_LVL);
|
|
||||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||||
I2CBB::unlock2();
|
I2CBB::unlock2();
|
||||||
}
|
}
|
||||||
@@ -241,16 +222,16 @@ void fusb_reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Flush the TX buffer */
|
/* Flush the TX buffer */
|
||||||
fusb_write_byte( FUSB_CONTROL0, 0x44);
|
fusb_write_byte(FUSB_CONTROL0, 0x44);
|
||||||
/* Flush the RX buffer */
|
/* Flush the RX buffer */
|
||||||
fusb_write_byte( FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH);
|
fusb_write_byte(FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH);
|
||||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||||
I2CBB::unlock2();
|
I2CBB::unlock2();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fusb_read_id() {
|
bool fusb_read_id() {
|
||||||
//Return true if read of the revision ID is sane
|
// Return true if read of the revision ID is sane
|
||||||
uint8_t version = 0;
|
uint8_t version = 0;
|
||||||
fusb_read_buf(FUSB_DEVICE_ID, 1, &version);
|
fusb_read_buf(FUSB_DEVICE_ID, 1, &version);
|
||||||
if (version == 0 || version == 0xFF)
|
if (version == 0 || version == 0xFF)
|
||||||
@@ -258,7 +239,7 @@ bool fusb_read_id() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
uint8_t fusb302_detect() {
|
uint8_t fusb302_detect() {
|
||||||
//Probe the I2C bus for its address
|
// Probe the I2C bus for its address
|
||||||
return I2CBB::probe(FUSB302B_ADDR);
|
return I2CBB::probe(FUSB302B_ADDR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,19 +8,18 @@
|
|||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "OLED.hpp"
|
#include "OLED.hpp"
|
||||||
|
|
||||||
static uint8_t logo_page[1024] __attribute__ ((section (".logo_page")));
|
static uint8_t logo_page[1024] __attribute__((section(".logo_page")));
|
||||||
|
|
||||||
// Logo header signature.
|
// Logo header signature.
|
||||||
#define LOGO_HEADER_VALUE 0xF00DAA55
|
#define LOGO_HEADER_VALUE 0xF00DAA55
|
||||||
|
|
||||||
uint8_t showBootLogoIfavailable() {
|
uint8_t showBootLogoIfavailable() {
|
||||||
// Do not show logo data if signature is not found.
|
// Do not show logo data if signature is not found.
|
||||||
if (LOGO_HEADER_VALUE != *(reinterpret_cast<const uint32_t*>(logo_page))) {
|
if (LOGO_HEADER_VALUE != *(reinterpret_cast<const uint32_t *>(logo_page))) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
OLED::drawAreaSwapped(0, 0, 96, 16, (uint8_t*) (logo_page + 4));
|
OLED::drawAreaSwapped(0, 0, 96, 16, (uint8_t *)(logo_page + 4));
|
||||||
OLED::refresh();
|
OLED::refresh();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,61 +43,61 @@
|
|||||||
#ifndef configSYSTICK_CLOCK_HZ
|
#ifndef configSYSTICK_CLOCK_HZ
|
||||||
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
|
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
|
||||||
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
#define portNVIC_SYSTICK_CLK_BIT (1UL << 2UL)
|
||||||
#else
|
#else
|
||||||
/* The way the SysTick is clocked is not modified in case it is not the same
|
/* The way the SysTick is clocked is not modified in case it is not the same
|
||||||
as the core. */
|
as the core. */
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 0 )
|
#define portNVIC_SYSTICK_CLK_BIT (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Constants required to manipulate the core. Registers first... */
|
/* Constants required to manipulate the core. Registers first... */
|
||||||
#define portNVIC_SYSTICK_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000e010 ) )
|
#define portNVIC_SYSTICK_CTRL_REG (*((volatile uint32_t *)0xe000e010))
|
||||||
#define portNVIC_SYSTICK_LOAD_REG ( * ( ( volatile uint32_t * ) 0xe000e014 ) )
|
#define portNVIC_SYSTICK_LOAD_REG (*((volatile uint32_t *)0xe000e014))
|
||||||
#define portNVIC_SYSTICK_CURRENT_VALUE_REG ( * ( ( volatile uint32_t * ) 0xe000e018 ) )
|
#define portNVIC_SYSTICK_CURRENT_VALUE_REG (*((volatile uint32_t *)0xe000e018))
|
||||||
#define portNVIC_SYSPRI2_REG ( * ( ( volatile uint32_t * ) 0xe000ed20 ) )
|
#define portNVIC_SYSPRI2_REG (*((volatile uint32_t *)0xe000ed20))
|
||||||
/* ...then bits in the registers. */
|
/* ...then bits in the registers. */
|
||||||
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
#define portNVIC_SYSTICK_INT_BIT (1UL << 1UL)
|
||||||
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
#define portNVIC_SYSTICK_ENABLE_BIT (1UL << 0UL)
|
||||||
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
#define portNVIC_SYSTICK_COUNT_FLAG_BIT (1UL << 16UL)
|
||||||
#define portNVIC_PENDSVCLEAR_BIT ( 1UL << 27UL )
|
#define portNVIC_PENDSVCLEAR_BIT (1UL << 27UL)
|
||||||
#define portNVIC_PEND_SYSTICK_CLEAR_BIT ( 1UL << 25UL )
|
#define portNVIC_PEND_SYSTICK_CLEAR_BIT (1UL << 25UL)
|
||||||
|
|
||||||
#define portNVIC_PENDSV_PRI ( ( ( uint32_t ) configKERNEL_INTERRUPT_PRIORITY ) << 16UL )
|
#define portNVIC_PENDSV_PRI (((uint32_t)configKERNEL_INTERRUPT_PRIORITY) << 16UL)
|
||||||
#define portNVIC_SYSTICK_PRI ( ( ( uint32_t ) configKERNEL_INTERRUPT_PRIORITY ) << 24UL )
|
#define portNVIC_SYSTICK_PRI (((uint32_t)configKERNEL_INTERRUPT_PRIORITY) << 24UL)
|
||||||
|
|
||||||
/* Constants required to check the validity of an interrupt priority. */
|
/* Constants required to check the validity of an interrupt priority. */
|
||||||
#define portFIRST_USER_INTERRUPT_NUMBER ( 16 )
|
#define portFIRST_USER_INTERRUPT_NUMBER (16)
|
||||||
#define portNVIC_IP_REGISTERS_OFFSET_16 ( 0xE000E3F0 )
|
#define portNVIC_IP_REGISTERS_OFFSET_16 (0xE000E3F0)
|
||||||
#define portAIRCR_REG ( * ( ( volatile uint32_t * ) 0xE000ED0C ) )
|
#define portAIRCR_REG (*((volatile uint32_t *)0xE000ED0C))
|
||||||
#define portMAX_8_BIT_VALUE ( ( uint8_t ) 0xff )
|
#define portMAX_8_BIT_VALUE ((uint8_t)0xff)
|
||||||
#define portTOP_BIT_OF_BYTE ( ( uint8_t ) 0x80 )
|
#define portTOP_BIT_OF_BYTE ((uint8_t)0x80)
|
||||||
#define portMAX_PRIGROUP_BITS ( ( uint8_t ) 7 )
|
#define portMAX_PRIGROUP_BITS ((uint8_t)7)
|
||||||
#define portPRIORITY_GROUP_MASK ( 0x07UL << 8UL )
|
#define portPRIORITY_GROUP_MASK (0x07UL << 8UL)
|
||||||
#define portPRIGROUP_SHIFT ( 8UL )
|
#define portPRIGROUP_SHIFT (8UL)
|
||||||
|
|
||||||
/* Masks off all bits but the VECTACTIVE bits in the ICSR register. */
|
/* Masks off all bits but the VECTACTIVE bits in the ICSR register. */
|
||||||
#define portVECTACTIVE_MASK ( 0xFFUL )
|
#define portVECTACTIVE_MASK (0xFFUL)
|
||||||
|
|
||||||
/* Constants required to set up the initial stack. */
|
/* Constants required to set up the initial stack. */
|
||||||
#define portINITIAL_XPSR ( 0x01000000UL )
|
#define portINITIAL_XPSR (0x01000000UL)
|
||||||
|
|
||||||
/* The systick is a 24-bit counter. */
|
/* The systick is a 24-bit counter. */
|
||||||
#define portMAX_24_BIT_NUMBER ( 0xffffffUL )
|
#define portMAX_24_BIT_NUMBER (0xffffffUL)
|
||||||
|
|
||||||
/* A fiddle factor to estimate the number of SysTick counts that would have
|
/* A fiddle factor to estimate the number of SysTick counts that would have
|
||||||
occurred while the SysTick counter is stopped during tickless idle
|
occurred while the SysTick counter is stopped during tickless idle
|
||||||
calculations. */
|
calculations. */
|
||||||
#define portMISSED_COUNTS_FACTOR ( 45UL )
|
#define portMISSED_COUNTS_FACTOR (45UL)
|
||||||
|
|
||||||
/* For strict compliance with the Cortex-M spec the task start address should
|
/* For strict compliance with the Cortex-M spec the task start address should
|
||||||
have bit-0 clear, as it is loaded into the PC on exit from an ISR. */
|
have bit-0 clear, as it is loaded into the PC on exit from an ISR. */
|
||||||
#define portSTART_ADDRESS_MASK ( ( StackType_t ) 0xfffffffeUL )
|
#define portSTART_ADDRESS_MASK ((StackType_t)0xfffffffeUL)
|
||||||
|
|
||||||
/* Let the user override the pre-loading of the initial LR with the address of
|
/* Let the user override the pre-loading of the initial LR with the address of
|
||||||
prvTaskExitError() in case it messes up unwinding of the stack in the
|
prvTaskExitError() in case it messes up unwinding of the stack in the
|
||||||
debugger. */
|
debugger. */
|
||||||
#ifdef configTASK_RETURN_ADDRESS
|
#ifdef configTASK_RETURN_ADDRESS
|
||||||
#define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS
|
#define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS
|
||||||
#else
|
#else
|
||||||
#define portTASK_RETURN_ADDRESS prvTaskExitError
|
#define portTASK_RETURN_ADDRESS prvTaskExitError
|
||||||
#endif
|
#endif
|
||||||
@@ -112,14 +112,14 @@ void vPortSetupTimerInterrupt(void);
|
|||||||
/*
|
/*
|
||||||
* Exception handlers.
|
* Exception handlers.
|
||||||
*/
|
*/
|
||||||
void xPortPendSVHandler(void) __attribute__ (( naked ));
|
void xPortPendSVHandler(void) __attribute__((naked));
|
||||||
void xPortSysTickHandler(void);
|
void xPortSysTickHandler(void);
|
||||||
void vPortSVCHandler(void) __attribute__ (( naked ));
|
void vPortSVCHandler(void) __attribute__((naked));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start first task is a separate function so it can be tested in isolation.
|
* Start first task is a separate function so it can be tested in isolation.
|
||||||
*/
|
*/
|
||||||
static void prvPortStartFirstTask(void) __attribute__ (( naked ));
|
static void prvPortStartFirstTask(void) __attribute__((naked));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Used to catch tasks that attempt to return from their implementing function.
|
* Used to catch tasks that attempt to return from their implementing function.
|
||||||
@@ -135,24 +135,24 @@ static UBaseType_t uxCriticalNesting = 0xaaaaaaaa;
|
|||||||
/*
|
/*
|
||||||
* The number of SysTick increments that make up one tick period.
|
* The number of SysTick increments that make up one tick period.
|
||||||
*/
|
*/
|
||||||
#if( configUSE_TICKLESS_IDLE == 1 )
|
#if (configUSE_TICKLESS_IDLE == 1)
|
||||||
static uint32_t ulTimerCountsForOneTick = 0;
|
static uint32_t ulTimerCountsForOneTick = 0;
|
||||||
#endif /* configUSE_TICKLESS_IDLE */
|
#endif /* configUSE_TICKLESS_IDLE */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The maximum number of tick periods that can be suppressed is limited by the
|
* The maximum number of tick periods that can be suppressed is limited by the
|
||||||
* 24 bit resolution of the SysTick timer.
|
* 24 bit resolution of the SysTick timer.
|
||||||
*/
|
*/
|
||||||
#if( configUSE_TICKLESS_IDLE == 1 )
|
#if (configUSE_TICKLESS_IDLE == 1)
|
||||||
static uint32_t xMaximumPossibleSuppressedTicks = 0;
|
static uint32_t xMaximumPossibleSuppressedTicks = 0;
|
||||||
#endif /* configUSE_TICKLESS_IDLE */
|
#endif /* configUSE_TICKLESS_IDLE */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compensate for the CPU cycles that pass while the SysTick is stopped (low
|
* Compensate for the CPU cycles that pass while the SysTick is stopped (low
|
||||||
* power functionality only.
|
* power functionality only.
|
||||||
*/
|
*/
|
||||||
#if( configUSE_TICKLESS_IDLE == 1 )
|
#if (configUSE_TICKLESS_IDLE == 1)
|
||||||
static uint32_t ulStoppedTimerCompensation = 0;
|
static uint32_t ulStoppedTimerCompensation = 0;
|
||||||
#endif /* configUSE_TICKLESS_IDLE */
|
#endif /* configUSE_TICKLESS_IDLE */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -160,11 +160,10 @@ static UBaseType_t uxCriticalNesting = 0xaaaaaaaa;
|
|||||||
* FreeRTOS API functions are not called from interrupts that have been assigned
|
* FreeRTOS API functions are not called from interrupts that have been assigned
|
||||||
* a priority above configMAX_SYSCALL_INTERRUPT_PRIORITY.
|
* a priority above configMAX_SYSCALL_INTERRUPT_PRIORITY.
|
||||||
*/
|
*/
|
||||||
#if( configASSERT_DEFINED == 1 )
|
#if (configASSERT_DEFINED == 1)
|
||||||
static uint8_t ucMaxSysCallPriority = 0;
|
static uint8_t ucMaxSysCallPriority = 0;
|
||||||
static uint32_t ulMaxPRIGROUPValue = 0;
|
static uint32_t ulMaxPRIGROUPValue = 0;
|
||||||
static const volatile uint8_t *const pcInterruptPriorityRegisters =
|
static const volatile uint8_t *const pcInterruptPriorityRegisters = (const volatile uint8_t *const)portNVIC_IP_REGISTERS_OFFSET_16;
|
||||||
(const volatile uint8_t* const ) portNVIC_IP_REGISTERS_OFFSET_16;
|
|
||||||
#endif /* configASSERT_DEFINED */
|
#endif /* configASSERT_DEFINED */
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
@@ -172,18 +171,17 @@ static const volatile uint8_t *const pcInterruptPriorityRegisters =
|
|||||||
/*
|
/*
|
||||||
* See header file for description.
|
* See header file for description.
|
||||||
*/
|
*/
|
||||||
StackType_t* pxPortInitialiseStack(StackType_t *pxTopOfStack,
|
StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters) {
|
||||||
TaskFunction_t pxCode, void *pvParameters) {
|
|
||||||
/* Simulate the stack frame as it would be created by a context switch
|
/* Simulate the stack frame as it would be created by a context switch
|
||||||
interrupt. */
|
interrupt. */
|
||||||
pxTopOfStack--; /* Offset added to account for the way the MCU uses the stack on entry/exit of interrupts. */
|
pxTopOfStack--; /* Offset added to account for the way the MCU uses the stack on entry/exit of interrupts. */
|
||||||
*pxTopOfStack = portINITIAL_XPSR; /* xPSR */
|
*pxTopOfStack = portINITIAL_XPSR; /* xPSR */
|
||||||
pxTopOfStack--;
|
pxTopOfStack--;
|
||||||
*pxTopOfStack = ((StackType_t) pxCode) & portSTART_ADDRESS_MASK; /* PC */
|
*pxTopOfStack = ((StackType_t)pxCode) & portSTART_ADDRESS_MASK; /* PC */
|
||||||
pxTopOfStack--;
|
pxTopOfStack--;
|
||||||
*pxTopOfStack = (StackType_t) portTASK_RETURN_ADDRESS; /* LR */
|
*pxTopOfStack = (StackType_t)portTASK_RETURN_ADDRESS; /* LR */
|
||||||
pxTopOfStack -= 5; /* R12, R3, R2 and R1. */
|
pxTopOfStack -= 5; /* R12, R3, R2 and R1. */
|
||||||
*pxTopOfStack = (StackType_t) pvParameters; /* R0 */
|
*pxTopOfStack = (StackType_t)pvParameters; /* R0 */
|
||||||
pxTopOfStack -= 8; /* R11, R10, R9, R8, R7, R6, R5 and R4. */
|
pxTopOfStack -= 8; /* R11, R10, R9, R8, R7, R6, R5 and R4. */
|
||||||
|
|
||||||
return pxTopOfStack;
|
return pxTopOfStack;
|
||||||
@@ -214,8 +212,7 @@ static void prvTaskExitError(void) {
|
|||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vPortSVCHandler(void) {
|
void vPortSVCHandler(void) {
|
||||||
__asm volatile (
|
__asm volatile(" ldr r3, pxCurrentTCBConst2 \n" /* Restore the context. */
|
||||||
" ldr r3, pxCurrentTCBConst2 \n" /* Restore the context. */
|
|
||||||
" ldr r1, [r3] \n" /* Use pxCurrentTCBConst to get the pxCurrentTCB address. */
|
" ldr r1, [r3] \n" /* Use pxCurrentTCBConst to get the pxCurrentTCB address. */
|
||||||
" ldr r0, [r1] \n" /* The first item in pxCurrentTCB is the task top of stack. */
|
" ldr r0, [r1] \n" /* The first item in pxCurrentTCB is the task top of stack. */
|
||||||
" ldmia r0!, {r4-r11} \n" /* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */
|
" ldmia r0!, {r4-r11} \n" /* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */
|
||||||
@@ -227,14 +224,12 @@ void vPortSVCHandler(void) {
|
|||||||
" bx r14 \n"
|
" bx r14 \n"
|
||||||
" \n"
|
" \n"
|
||||||
" .align 4 \n"
|
" .align 4 \n"
|
||||||
"pxCurrentTCBConst2: .word pxCurrentTCB \n"
|
"pxCurrentTCBConst2: .word pxCurrentTCB \n");
|
||||||
);
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static void prvPortStartFirstTask(void) {
|
static void prvPortStartFirstTask(void) {
|
||||||
__asm volatile(
|
__asm volatile(" ldr r0, =0xE000ED08 \n" /* Use the NVIC offset register to locate the stack. */
|
||||||
" ldr r0, =0xE000ED08 \n" /* Use the NVIC offset register to locate the stack. */
|
|
||||||
" ldr r0, [r0] \n"
|
" ldr r0, [r0] \n"
|
||||||
" ldr r0, [r0] \n"
|
" ldr r0, [r0] \n"
|
||||||
" msr msp, r0 \n" /* Set the msp back to the start of the stack. */
|
" msr msp, r0 \n" /* Set the msp back to the start of the stack. */
|
||||||
@@ -243,8 +238,7 @@ static void prvPortStartFirstTask(void) {
|
|||||||
" dsb \n"
|
" dsb \n"
|
||||||
" isb \n"
|
" isb \n"
|
||||||
" svc 0 \n" /* System call to start first task. */
|
" svc 0 \n" /* System call to start first task. */
|
||||||
" nop \n"
|
" nop \n");
|
||||||
);
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -256,12 +250,10 @@ BaseType_t xPortStartScheduler(void) {
|
|||||||
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
|
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
|
||||||
configASSERT(configMAX_SYSCALL_INTERRUPT_PRIORITY);
|
configASSERT(configMAX_SYSCALL_INTERRUPT_PRIORITY);
|
||||||
|
|
||||||
#if( configASSERT_DEFINED == 1 )
|
#if (configASSERT_DEFINED == 1)
|
||||||
{
|
{
|
||||||
volatile uint32_t ulOriginalPriority;
|
volatile uint32_t ulOriginalPriority;
|
||||||
volatile uint8_t *const pucFirstUserPriorityRegister =
|
volatile uint8_t *const pucFirstUserPriorityRegister = (volatile uint8_t *const)(portNVIC_IP_REGISTERS_OFFSET_16 + portFIRST_USER_INTERRUPT_NUMBER);
|
||||||
(volatile uint8_t* const ) ( portNVIC_IP_REGISTERS_OFFSET_16
|
|
||||||
+ portFIRST_USER_INTERRUPT_NUMBER);
|
|
||||||
volatile uint8_t ucMaxPriorityValue;
|
volatile uint8_t ucMaxPriorityValue;
|
||||||
|
|
||||||
/* Determine the maximum priority from which ISR safe FreeRTOS API
|
/* Determine the maximum priority from which ISR safe FreeRTOS API
|
||||||
@@ -280,15 +272,14 @@ BaseType_t xPortStartScheduler(void) {
|
|||||||
ucMaxPriorityValue = *pucFirstUserPriorityRegister;
|
ucMaxPriorityValue = *pucFirstUserPriorityRegister;
|
||||||
|
|
||||||
/* Use the same mask on the maximum system call priority. */
|
/* Use the same mask on the maximum system call priority. */
|
||||||
ucMaxSysCallPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY
|
ucMaxSysCallPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY & ucMaxPriorityValue;
|
||||||
& ucMaxPriorityValue;
|
|
||||||
|
|
||||||
/* Calculate the maximum acceptable priority group value for the number
|
/* Calculate the maximum acceptable priority group value for the number
|
||||||
of bits read back. */
|
of bits read back. */
|
||||||
ulMaxPRIGROUPValue = portMAX_PRIGROUP_BITS;
|
ulMaxPRIGROUPValue = portMAX_PRIGROUP_BITS;
|
||||||
while ((ucMaxPriorityValue & portTOP_BIT_OF_BYTE) == portTOP_BIT_OF_BYTE) {
|
while ((ucMaxPriorityValue & portTOP_BIT_OF_BYTE) == portTOP_BIT_OF_BYTE) {
|
||||||
ulMaxPRIGROUPValue--;
|
ulMaxPRIGROUPValue--;
|
||||||
ucMaxPriorityValue <<= (uint8_t) 0x01;
|
ucMaxPriorityValue <<= (uint8_t)0x01;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __NVIC_PRIO_BITS
|
#ifdef __NVIC_PRIO_BITS
|
||||||
@@ -296,18 +287,18 @@ BaseType_t xPortStartScheduler(void) {
|
|||||||
/* Check the CMSIS configuration that defines the number of
|
/* Check the CMSIS configuration that defines the number of
|
||||||
priority bits matches the number of priority bits actually queried
|
priority bits matches the number of priority bits actually queried
|
||||||
from the hardware. */
|
from the hardware. */
|
||||||
configASSERT( ( portMAX_PRIGROUP_BITS - ulMaxPRIGROUPValue ) == __NVIC_PRIO_BITS );
|
configASSERT((portMAX_PRIGROUP_BITS - ulMaxPRIGROUPValue) == __NVIC_PRIO_BITS);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef configPRIO_BITS
|
#ifdef configPRIO_BITS
|
||||||
{
|
{
|
||||||
/* Check the FreeRTOS configuration that defines the number of
|
/* Check the FreeRTOS configuration that defines the number of
|
||||||
priority bits matches the number of priority bits actually queried
|
priority bits matches the number of priority bits actually queried
|
||||||
from the hardware. */
|
from the hardware. */
|
||||||
configASSERT( ( portMAX_PRIGROUP_BITS - ulMaxPRIGROUPValue ) == configPRIO_BITS );
|
configASSERT((portMAX_PRIGROUP_BITS - ulMaxPRIGROUPValue) == configPRIO_BITS);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Shift the priority group value back to its position within the AIRCR
|
/* Shift the priority group value back to its position within the AIRCR
|
||||||
register. */
|
register. */
|
||||||
@@ -365,7 +356,7 @@ void vPortEnterCritical(void) {
|
|||||||
the critical nesting count is 1 to protect against recursive calls if the
|
the critical nesting count is 1 to protect against recursive calls if the
|
||||||
assert function also uses a critical section. */
|
assert function also uses a critical section. */
|
||||||
if (uxCriticalNesting == 1) {
|
if (uxCriticalNesting == 1) {
|
||||||
configASSERT(( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK) == 0);
|
configASSERT((portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK) == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
@@ -382,9 +373,7 @@ void vPortExitCritical(void) {
|
|||||||
void xPortPendSVHandler(void) {
|
void xPortPendSVHandler(void) {
|
||||||
/* This is a naked function. */
|
/* This is a naked function. */
|
||||||
|
|
||||||
__asm volatile
|
__asm volatile(" mrs r0, psp \n"
|
||||||
(
|
|
||||||
" mrs r0, psp \n"
|
|
||||||
" isb \n"
|
" isb \n"
|
||||||
" \n"
|
" \n"
|
||||||
" ldr r3, pxCurrentTCBConst \n" /* Get the location of the current TCB. */
|
" ldr r3, pxCurrentTCBConst \n" /* Get the location of the current TCB. */
|
||||||
@@ -409,9 +398,7 @@ void xPortPendSVHandler(void) {
|
|||||||
" bx r14 \n"
|
" bx r14 \n"
|
||||||
" \n"
|
" \n"
|
||||||
" .align 4 \n"
|
" .align 4 \n"
|
||||||
"pxCurrentTCBConst: .word pxCurrentTCB \n"
|
"pxCurrentTCBConst: .word pxCurrentTCB \n" ::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY));
|
||||||
::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -433,16 +420,14 @@ void xPortSysTickHandler(void) {
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
#if( configUSE_TICKLESS_IDLE == 1 )
|
#if (configUSE_TICKLESS_IDLE == 1)
|
||||||
|
|
||||||
__attribute__((weak)) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
__attribute__((weak)) void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime) {
|
||||||
{
|
|
||||||
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
|
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
|
||||||
TickType_t xModifiableIdleTime;
|
TickType_t xModifiableIdleTime;
|
||||||
|
|
||||||
/* Make sure the SysTick reload value does not overflow the counter. */
|
/* Make sure the SysTick reload value does not overflow the counter. */
|
||||||
if( xExpectedIdleTime > xMaximumPossibleSuppressedTicks )
|
if (xExpectedIdleTime > xMaximumPossibleSuppressedTicks) {
|
||||||
{
|
|
||||||
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,22 +440,20 @@ void xPortSysTickHandler(void) {
|
|||||||
/* Calculate the reload value required to wait xExpectedIdleTime
|
/* Calculate the reload value required to wait xExpectedIdleTime
|
||||||
tick periods. -1 is used because this code will execute part way
|
tick periods. -1 is used because this code will execute part way
|
||||||
through one of the tick periods. */
|
through one of the tick periods. */
|
||||||
ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + (ulTimerCountsForOneTick * (xExpectedIdleTime - 1UL));
|
||||||
if( ulReloadValue > ulStoppedTimerCompensation )
|
if (ulReloadValue > ulStoppedTimerCompensation) {
|
||||||
{
|
|
||||||
ulReloadValue -= ulStoppedTimerCompensation;
|
ulReloadValue -= ulStoppedTimerCompensation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
||||||
method as that will mask interrupts that should exit sleep mode. */
|
method as that will mask interrupts that should exit sleep mode. */
|
||||||
__asm volatile( "cpsid i" ::: "memory" );
|
__asm volatile("cpsid i" ::: "memory");
|
||||||
__asm volatile( "dsb" );
|
__asm volatile("dsb");
|
||||||
__asm volatile( "isb" );
|
__asm volatile("isb");
|
||||||
|
|
||||||
/* If a context switch is pending or a task is waiting for the scheduler
|
/* If a context switch is pending or a task is waiting for the scheduler
|
||||||
to be unsuspended then abandon the low power entry. */
|
to be unsuspended then abandon the low power entry. */
|
||||||
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
if (eTaskConfirmSleepModeStatus() == eAbortSleep) {
|
||||||
{
|
|
||||||
/* Restart from whatever is left in the count register to complete
|
/* Restart from whatever is left in the count register to complete
|
||||||
this tick period. */
|
this tick period. */
|
||||||
portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
@@ -484,10 +467,8 @@ void xPortSysTickHandler(void) {
|
|||||||
|
|
||||||
/* Re-enable interrupts - see comments above the cpsid instruction()
|
/* Re-enable interrupts - see comments above the cpsid instruction()
|
||||||
above. */
|
above. */
|
||||||
__asm volatile( "cpsie i" ::: "memory" );
|
__asm volatile("cpsie i" ::: "memory");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Set the new reload value. */
|
/* Set the new reload value. */
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
||||||
|
|
||||||
@@ -504,29 +485,28 @@ void xPortSysTickHandler(void) {
|
|||||||
should not be executed again. However, the original expected idle
|
should not be executed again. However, the original expected idle
|
||||||
time variable must remain unmodified, so a copy is taken. */
|
time variable must remain unmodified, so a copy is taken. */
|
||||||
xModifiableIdleTime = xExpectedIdleTime;
|
xModifiableIdleTime = xExpectedIdleTime;
|
||||||
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
configPRE_SLEEP_PROCESSING(xModifiableIdleTime);
|
||||||
if( xModifiableIdleTime > 0 )
|
if (xModifiableIdleTime > 0) {
|
||||||
{
|
__asm volatile("dsb" ::: "memory");
|
||||||
__asm volatile( "dsb" ::: "memory" );
|
__asm volatile("wfi");
|
||||||
__asm volatile( "wfi" );
|
__asm volatile("isb");
|
||||||
__asm volatile( "isb" );
|
|
||||||
}
|
}
|
||||||
configPOST_SLEEP_PROCESSING( xExpectedIdleTime );
|
configPOST_SLEEP_PROCESSING(xExpectedIdleTime);
|
||||||
|
|
||||||
/* Re-enable interrupts to allow the interrupt that brought the MCU
|
/* Re-enable interrupts to allow the interrupt that brought the MCU
|
||||||
out of sleep mode to execute immediately. see comments above
|
out of sleep mode to execute immediately. see comments above
|
||||||
__disable_interrupt() call above. */
|
__disable_interrupt() call above. */
|
||||||
__asm volatile( "cpsie i" ::: "memory" );
|
__asm volatile("cpsie i" ::: "memory");
|
||||||
__asm volatile( "dsb" );
|
__asm volatile("dsb");
|
||||||
__asm volatile( "isb" );
|
__asm volatile("isb");
|
||||||
|
|
||||||
/* Disable interrupts again because the clock is about to be stopped
|
/* Disable interrupts again because the clock is about to be stopped
|
||||||
and interrupts that execute while the clock is stopped will increase
|
and interrupts that execute while the clock is stopped will increase
|
||||||
any slippage between the time maintained by the RTOS and calendar
|
any slippage between the time maintained by the RTOS and calendar
|
||||||
time. */
|
time. */
|
||||||
__asm volatile( "cpsid i" ::: "memory" );
|
__asm volatile("cpsid i" ::: "memory");
|
||||||
__asm volatile( "dsb" );
|
__asm volatile("dsb");
|
||||||
__asm volatile( "isb" );
|
__asm volatile("isb");
|
||||||
|
|
||||||
/* Disable the SysTick clock without reading the
|
/* Disable the SysTick clock without reading the
|
||||||
portNVIC_SYSTICK_CTRL_REG register to ensure the
|
portNVIC_SYSTICK_CTRL_REG register to ensure the
|
||||||
@@ -535,29 +515,27 @@ void xPortSysTickHandler(void) {
|
|||||||
be, but using the tickless mode will inevitably result in some tiny
|
be, but using the tickless mode will inevitably result in some tiny
|
||||||
drift of the time maintained by the kernel with respect to calendar
|
drift of the time maintained by the kernel with respect to calendar
|
||||||
time*/
|
time*/
|
||||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT );
|
portNVIC_SYSTICK_CTRL_REG = (portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT);
|
||||||
|
|
||||||
/* Determine if the SysTick clock has already counted to zero and
|
/* Determine if the SysTick clock has already counted to zero and
|
||||||
been set back to the current reload value (the reload back being
|
been set back to the current reload value (the reload back being
|
||||||
correct for the entire expected idle time) or if the SysTick is yet
|
correct for the entire expected idle time) or if the SysTick is yet
|
||||||
to count to zero (in which case an interrupt other than the SysTick
|
to count to zero (in which case an interrupt other than the SysTick
|
||||||
must have brought the system out of sleep mode). */
|
must have brought the system out of sleep mode). */
|
||||||
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
if ((portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT) != 0) {
|
||||||
{
|
|
||||||
uint32_t ulCalculatedLoadValue;
|
uint32_t ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* The tick interrupt is already pending, and the SysTick count
|
/* The tick interrupt is already pending, and the SysTick count
|
||||||
reloaded with ulReloadValue. Reset the
|
reloaded with ulReloadValue. Reset the
|
||||||
portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick
|
portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick
|
||||||
period. */
|
period. */
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
ulCalculatedLoadValue = (ulTimerCountsForOneTick - 1UL) - (ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG);
|
||||||
|
|
||||||
/* Don't allow a tiny value, or values that have somehow
|
/* Don't allow a tiny value, or values that have somehow
|
||||||
underflowed because the post sleep hook did something
|
underflowed because the post sleep hook did something
|
||||||
that took too long. */
|
that took too long. */
|
||||||
if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
if ((ulCalculatedLoadValue < ulStoppedTimerCompensation) || (ulCalculatedLoadValue > ulTimerCountsForOneTick)) {
|
||||||
{
|
ulCalculatedLoadValue = (ulTimerCountsForOneTick - 1UL);
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
||||||
@@ -566,14 +544,12 @@ void xPortSysTickHandler(void) {
|
|||||||
function exits, the tick value maintained by the tick is stepped
|
function exits, the tick value maintained by the tick is stepped
|
||||||
forward by one less than the time spent waiting. */
|
forward by one less than the time spent waiting. */
|
||||||
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Something other than the tick interrupt ended the sleep.
|
/* Something other than the tick interrupt ended the sleep.
|
||||||
Work out how long the sleep lasted rounded to complete tick
|
Work out how long the sleep lasted rounded to complete tick
|
||||||
periods (not the ulReload value which accounted for part
|
periods (not the ulReload value which accounted for part
|
||||||
ticks). */
|
ticks). */
|
||||||
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
ulCompletedSysTickDecrements = (xExpectedIdleTime * ulTimerCountsForOneTick) - portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
|
||||||
/* How many complete tick periods passed while the processor
|
/* How many complete tick periods passed while the processor
|
||||||
was waiting? */
|
was waiting? */
|
||||||
@@ -581,7 +557,7 @@ void xPortSysTickHandler(void) {
|
|||||||
|
|
||||||
/* The reload value is set to whatever fraction of a single tick
|
/* The reload value is set to whatever fraction of a single tick
|
||||||
period remains. */
|
period remains. */
|
||||||
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
portNVIC_SYSTICK_LOAD_REG = ((ulCompleteTickPeriods + 1UL) * ulTimerCountsForOneTick) - ulCompletedSysTickDecrements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG
|
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG
|
||||||
@@ -589,13 +565,13 @@ void xPortSysTickHandler(void) {
|
|||||||
value. */
|
value. */
|
||||||
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
vTaskStepTick( ulCompleteTickPeriods );
|
vTaskStepTick(ulCompleteTickPeriods);
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
|
||||||
/* Exit with interrupts enabled. */
|
/* Exit with interrupts enabled. */
|
||||||
__asm volatile( "cpsie i" ::: "memory" );
|
__asm volatile("cpsie i" ::: "memory");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* configUSE_TICKLESS_IDLE */
|
#endif /* configUSE_TICKLESS_IDLE */
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
@@ -604,36 +580,34 @@ void xPortSysTickHandler(void) {
|
|||||||
* Setup the systick timer to generate the tick interrupts at the required
|
* Setup the systick timer to generate the tick interrupts at the required
|
||||||
* frequency.
|
* frequency.
|
||||||
*/
|
*/
|
||||||
__attribute__(( weak )) void vPortSetupTimerInterrupt(void) {
|
__attribute__((weak)) void vPortSetupTimerInterrupt(void) {
|
||||||
/* Calculate the constants required to configure the tick interrupt. */
|
/* Calculate the constants required to configure the tick interrupt. */
|
||||||
#if( configUSE_TICKLESS_IDLE == 1 )
|
#if (configUSE_TICKLESS_IDLE == 1)
|
||||||
{
|
{
|
||||||
ulTimerCountsForOneTick = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ );
|
ulTimerCountsForOneTick = (configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ);
|
||||||
xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick;
|
xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick;
|
||||||
ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / ( configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ );
|
ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / (configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ);
|
||||||
}
|
}
|
||||||
#endif /* configUSE_TICKLESS_IDLE */
|
#endif /* configUSE_TICKLESS_IDLE */
|
||||||
|
|
||||||
/* Stop and clear the SysTick. */
|
/* Stop and clear the SysTick. */
|
||||||
portNVIC_SYSTICK_CTRL_REG = 0UL;
|
portNVIC_SYSTICK_CTRL_REG = 0UL;
|
||||||
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
||||||
|
|
||||||
/* Configure SysTick to interrupt at the requested rate. */
|
/* Configure SysTick to interrupt at the requested rate. */
|
||||||
portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ)
|
portNVIC_SYSTICK_LOAD_REG = (configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ) - 1UL;
|
||||||
- 1UL;
|
portNVIC_SYSTICK_CTRL_REG = (portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT);
|
||||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT
|
|
||||||
| portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT);
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
#if( configASSERT_DEFINED == 1 )
|
#if (configASSERT_DEFINED == 1)
|
||||||
|
|
||||||
void vPortValidateInterruptPriority(void) {
|
void vPortValidateInterruptPriority(void) {
|
||||||
uint32_t ulCurrentInterrupt;
|
uint32_t ulCurrentInterrupt;
|
||||||
uint8_t ucCurrentPriority;
|
uint8_t ucCurrentPriority;
|
||||||
|
|
||||||
/* Obtain the number of the currently executing interrupt. */
|
/* Obtain the number of the currently executing interrupt. */
|
||||||
__asm volatile( "mrs %0, ipsr" : "=r"( ulCurrentInterrupt ) :: "memory" );
|
__asm volatile("mrs %0, ipsr" : "=r"(ulCurrentInterrupt)::"memory");
|
||||||
|
|
||||||
/* Is the interrupt number a user defined interrupt? */
|
/* Is the interrupt number a user defined interrupt? */
|
||||||
if (ulCurrentInterrupt >= portFIRST_USER_INTERRUPT_NUMBER) {
|
if (ulCurrentInterrupt >= portFIRST_USER_INTERRUPT_NUMBER) {
|
||||||
@@ -679,9 +653,7 @@ void vPortValidateInterruptPriority(void) {
|
|||||||
scheduler. Note however that some vendor specific peripheral libraries
|
scheduler. Note however that some vendor specific peripheral libraries
|
||||||
assume a non-zero priority group setting, in which cases using a value
|
assume a non-zero priority group setting, in which cases using a value
|
||||||
of zero will result in unpredictable behaviour. */
|
of zero will result in unpredictable behaviour. */
|
||||||
configASSERT(
|
configASSERT((portAIRCR_REG & portPRIORITY_GROUP_MASK) <= ulMaxPRIGROUPValue);
|
||||||
( portAIRCR_REG & portPRIORITY_GROUP_MASK) <= ulMaxPRIGROUPValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* configASSERT_DEFINED */
|
#endif /* configASSERT_DEFINED */
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
|
#include "I2C_Wrapper.hpp"
|
||||||
#include "QC3.h"
|
#include "QC3.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
#include "fusbpd.h"
|
||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
#include "power.hpp"
|
#include "power.hpp"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "I2C_Wrapper.hpp"
|
|
||||||
#include "fusbpd.h"
|
|
||||||
|
|
||||||
// Initialisation to be performed with scheduler active
|
// Initialisation to be performed with scheduler active
|
||||||
void postRToSInit() {
|
void postRToSInit() {
|
||||||
#ifdef POW_PD
|
#ifdef POW_PD
|
||||||
if (usb_pd_detect() == true) {
|
if (usb_pd_detect() == true) {
|
||||||
//Spawn all of the USB-C processors
|
// Spawn all of the USB-C processors
|
||||||
fusb302_start_processing();
|
fusb302_start_processing();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
* Author: Ralim
|
* Author: Ralim
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <I2C_Wrapper.hpp>
|
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "Setup.h"
|
|
||||||
#include "Pins.h"
|
|
||||||
#include "I2CBB.hpp"
|
#include "I2CBB.hpp"
|
||||||
#include "fusbpd.h"
|
|
||||||
#include "Model_Config.h"
|
#include "Model_Config.h"
|
||||||
|
#include "Pins.h"
|
||||||
|
#include "Setup.h"
|
||||||
|
#include "fusbpd.h"
|
||||||
|
#include <I2C_Wrapper.hpp>
|
||||||
void preRToSInit() {
|
void preRToSInit() {
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick.
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
#include "Pins.h"
|
#include "Pins.h"
|
||||||
#include "stm32f1xx_hal.h"
|
|
||||||
#include "Setup.h"
|
#include "Setup.h"
|
||||||
|
#include "stm32f1xx_hal.h"
|
||||||
/**
|
/**
|
||||||
* Initializes the Global MSP.
|
* Initializes the Global MSP.
|
||||||
*/
|
*/
|
||||||
void HAL_MspInit(void) {
|
void HAL_MspInit(void) {
|
||||||
__HAL_RCC_AFIO_CLK_ENABLE()
|
__HAL_RCC_AFIO_CLK_ENABLE();
|
||||||
;
|
|
||||||
|
|
||||||
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
|
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
|
||||||
|
|
||||||
@@ -25,15 +24,13 @@ void HAL_MspInit(void) {
|
|||||||
HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
|
HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
|
||||||
/* SysTick_IRQn interrupt configuration */
|
/* SysTick_IRQn interrupt configuration */
|
||||||
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
|
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) {
|
void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) {
|
||||||
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
if (hadc->Instance == ADC1) {
|
if (hadc->Instance == ADC1) {
|
||||||
__HAL_RCC_ADC1_CLK_ENABLE()
|
__HAL_RCC_ADC1_CLK_ENABLE();
|
||||||
;
|
|
||||||
|
|
||||||
/* ADC1 DMA Init */
|
/* ADC1 DMA Init */
|
||||||
/* ADC1 Init */
|
/* ADC1 Init */
|
||||||
@@ -53,8 +50,7 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) {
|
|||||||
HAL_NVIC_SetPriority(ADC1_2_IRQn, 15, 0);
|
HAL_NVIC_SetPriority(ADC1_2_IRQn, 15, 0);
|
||||||
HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
|
HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
|
||||||
} else {
|
} else {
|
||||||
__HAL_RCC_ADC2_CLK_ENABLE()
|
__HAL_RCC_ADC2_CLK_ENABLE();
|
||||||
;
|
|
||||||
|
|
||||||
/**ADC2 GPIO Configuration
|
/**ADC2 GPIO Configuration
|
||||||
PB0 ------> ADC2_IN8
|
PB0 ------> ADC2_IN8
|
||||||
@@ -74,7 +70,6 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) {
|
|||||||
HAL_NVIC_SetPriority(ADC1_2_IRQn, 15, 0);
|
HAL_NVIC_SetPriority(ADC1_2_IRQn, 15, 0);
|
||||||
HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
|
HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) {
|
void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) {
|
||||||
@@ -91,8 +86,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) {
|
|||||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
/* Peripheral clock enable */
|
/* Peripheral clock enable */
|
||||||
__HAL_RCC_I2C1_CLK_ENABLE()
|
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||||
;
|
|
||||||
/* I2C1 DMA Init */
|
/* I2C1 DMA Init */
|
||||||
/* I2C1_RX Init */
|
/* I2C1_RX Init */
|
||||||
hdma_i2c1_rx.Instance = DMA1_Channel7;
|
hdma_i2c1_rx.Instance = DMA1_Channel7;
|
||||||
@@ -125,17 +119,14 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) {
|
|||||||
HAL_NVIC_EnableIRQ(I2C1_EV_IRQn);
|
HAL_NVIC_EnableIRQ(I2C1_EV_IRQn);
|
||||||
HAL_NVIC_SetPriority(I2C1_ER_IRQn, 15, 0);
|
HAL_NVIC_SetPriority(I2C1_ER_IRQn, 15, 0);
|
||||||
HAL_NVIC_EnableIRQ(I2C1_ER_IRQn);
|
HAL_NVIC_EnableIRQ(I2C1_ER_IRQn);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim_base) {
|
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim_base) {
|
||||||
if (htim_base->Instance == TIM3) {
|
if (htim_base->Instance == TIM3) {
|
||||||
/* Peripheral clock enable */
|
/* Peripheral clock enable */
|
||||||
__HAL_RCC_TIM3_CLK_ENABLE()
|
__HAL_RCC_TIM3_CLK_ENABLE();
|
||||||
;
|
|
||||||
} else if (htim_base->Instance == TIM2) {
|
} else if (htim_base->Instance == TIM2) {
|
||||||
/* Peripheral clock enable */
|
/* Peripheral clock enable */
|
||||||
__HAL_RCC_TIM2_CLK_ENABLE()
|
__HAL_RCC_TIM2_CLK_ENABLE();
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
|
|||||||
uwTimclock = HAL_RCC_GetPCLK2Freq();
|
uwTimclock = HAL_RCC_GetPCLK2Freq();
|
||||||
|
|
||||||
/* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */
|
/* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */
|
||||||
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000) - 1);
|
uwPrescalerValue = (uint32_t)((uwTimclock / 1000000) - 1);
|
||||||
|
|
||||||
/* Initialize TIM1 */
|
/* Initialize TIM1 */
|
||||||
htim1.Instance = TIM1;
|
htim1.Instance = TIM1;
|
||||||
|
|||||||
@@ -1,42 +1,34 @@
|
|||||||
// This is the stock standard STM interrupt file full of handlers
|
// This is the stock standard STM interrupt file full of handlers
|
||||||
#include "stm32f1xx_hal.h"
|
|
||||||
#include "stm32f1xx.h"
|
|
||||||
#include "stm32f1xx_it.h"
|
#include "stm32f1xx_it.h"
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "Setup.h"
|
#include "Setup.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#include "stm32f1xx.h"
|
||||||
|
#include "stm32f1xx_hal.h"
|
||||||
|
|
||||||
extern TIM_HandleTypeDef htim1; //used for the systick
|
extern TIM_HandleTypeDef htim1; // used for the systick
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* Cortex-M3 Processor Interruption and Exception Handlers */
|
/* Cortex-M3 Processor Interruption and Exception Handlers */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
void NMI_Handler(void) {
|
void NMI_Handler(void) {}
|
||||||
}
|
|
||||||
|
|
||||||
//We have the assembly for a breakpoint trigger here to halt the system when a debugger is connected
|
// We have the assembly for a breakpoint trigger here to halt the system when a debugger is connected
|
||||||
// Hardfault handler, often a screwup in the code
|
// Hardfault handler, often a screwup in the code
|
||||||
void HardFault_Handler(void) {
|
void HardFault_Handler(void) {}
|
||||||
}
|
|
||||||
|
|
||||||
// Memory management unit had an error
|
// Memory management unit had an error
|
||||||
void MemManage_Handler(void) {
|
void MemManage_Handler(void) {}
|
||||||
}
|
|
||||||
|
|
||||||
// Prefetcher or busfault occured
|
// Prefetcher or busfault occured
|
||||||
void BusFault_Handler(void) {
|
void BusFault_Handler(void) {}
|
||||||
}
|
|
||||||
|
|
||||||
void UsageFault_Handler(void) {
|
void UsageFault_Handler(void) {}
|
||||||
}
|
|
||||||
|
|
||||||
void DebugMon_Handler(void) {
|
void DebugMon_Handler(void) {}
|
||||||
}
|
|
||||||
|
|
||||||
// Systick is used by FreeRTOS tick
|
// Systick is used by FreeRTOS tick
|
||||||
void SysTick_Handler(void) {
|
void SysTick_Handler(void) { osSystickHandler(); }
|
||||||
osSystickHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* STM32F1xx Peripheral Interrupt Handlers */
|
/* STM32F1xx Peripheral Interrupt Handlers */
|
||||||
@@ -46,42 +38,22 @@ void SysTick_Handler(void) {
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// DMA used to move the ADC readings into system ram
|
// DMA used to move the ADC readings into system ram
|
||||||
void DMA1_Channel1_IRQHandler(void) {
|
void DMA1_Channel1_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_adc1); }
|
||||||
HAL_DMA_IRQHandler(&hdma_adc1);
|
// ADC interrupt used for DMA
|
||||||
}
|
void ADC1_2_IRQHandler(void) { HAL_ADC_IRQHandler(&hadc1); }
|
||||||
//ADC interrupt used for DMA
|
|
||||||
void ADC1_2_IRQHandler(void) {
|
|
||||||
HAL_ADC_IRQHandler(&hadc1);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Timer 1 has overflowed, used for HAL ticks
|
// Timer 1 has overflowed, used for HAL ticks
|
||||||
void TIM1_UP_IRQHandler(void) {
|
void TIM1_UP_IRQHandler(void) { HAL_TIM_IRQHandler(&htim1); }
|
||||||
HAL_TIM_IRQHandler(&htim1);
|
// Timer 3 is used for the PWM output to the tip
|
||||||
}
|
void TIM3_IRQHandler(void) { HAL_TIM_IRQHandler(&htim3); }
|
||||||
//Timer 3 is used for the PWM output to the tip
|
|
||||||
void TIM3_IRQHandler(void) {
|
|
||||||
HAL_TIM_IRQHandler(&htim3);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Timer 2 is used for co-ordination of PWM & ADC
|
// Timer 2 is used for co-ordination of PWM & ADC
|
||||||
void TIM2_IRQHandler(void) {
|
void TIM2_IRQHandler(void) { HAL_TIM_IRQHandler(&htim2); }
|
||||||
HAL_TIM_IRQHandler(&htim2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void I2C1_EV_IRQHandler(void) {
|
void I2C1_EV_IRQHandler(void) { HAL_I2C_EV_IRQHandler(&hi2c1); }
|
||||||
HAL_I2C_EV_IRQHandler(&hi2c1);
|
void I2C1_ER_IRQHandler(void) { HAL_I2C_ER_IRQHandler(&hi2c1); }
|
||||||
}
|
|
||||||
void I2C1_ER_IRQHandler(void) {
|
|
||||||
HAL_I2C_ER_IRQHandler(&hi2c1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DMA1_Channel6_IRQHandler(void) {
|
void DMA1_Channel6_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_i2c1_tx); }
|
||||||
HAL_DMA_IRQHandler(&hdma_i2c1_tx);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DMA1_Channel7_IRQHandler(void) {
|
void DMA1_Channel7_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_i2c1_rx); }
|
||||||
HAL_DMA_IRQHandler(&hdma_i2c1_rx);
|
void EXTI9_5_IRQHandler(void) { HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9); }
|
||||||
}
|
|
||||||
void EXTI9_5_IRQHandler(void) {
|
|
||||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
// And as such, is BSD licneced from STM
|
// And as such, is BSD licneced from STM
|
||||||
#include "stm32f1xx.h"
|
#include "stm32f1xx.h"
|
||||||
|
|
||||||
#if !defined (HSI_VALUE)
|
#if !defined(HSI_VALUE)
|
||||||
#define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz.
|
#define HSI_VALUE \
|
||||||
|
8000000U /*!< Default value of the Internal oscillator in Hz. \
|
||||||
This value can be provided and adapted by the user application. */
|
This value can be provided and adapted by the user application. */
|
||||||
#endif /* HSI_VALUE */
|
#endif /* HSI_VALUE */
|
||||||
|
|
||||||
@@ -13,23 +14,23 @@
|
|||||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||||
|
|
||||||
#ifndef VECT_TAB_OFFSET
|
#ifndef VECT_TAB_OFFSET
|
||||||
#define VECT_TAB_OFFSET 0x00004000U /*!< Vector Table base offset field.
|
#define VECT_TAB_OFFSET \
|
||||||
|
0x00004000U /*!< Vector Table base offset field. \
|
||||||
This value must be a multiple of 0x200. */
|
This value must be a multiple of 0x200. */
|
||||||
//We offset this by 0x4000 to because of the bootloader
|
// We offset this by 0x4000 to because of the bootloader
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Clock Definitions
|
* Clock Definitions
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
#if defined(STM32F100xB) ||defined(STM32F100xE)
|
#if defined(STM32F100xB) || defined(STM32F100xE)
|
||||||
uint32_t SystemCoreClock = 24000000U; /*!< System Clock Frequency (Core Clock) */
|
uint32_t SystemCoreClock = 24000000U; /*!< System Clock Frequency (Core Clock) */
|
||||||
#else /*!< HSI Selected as System Clock source */
|
#else /*!< HSI Selected as System Clock source */
|
||||||
uint32_t SystemCoreClock = 64000000U; /*!< System Clock Frequency (Core Clock) */
|
uint32_t SystemCoreClock = 64000000U; /*!< System Clock Frequency (Core Clock) */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const uint8_t AHBPrescTable[16U] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7,
|
const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||||
8, 9 };
|
const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||||
const uint8_t APBPrescTable[8U] = { 0, 0, 0, 0, 1, 2, 3, 4 };
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Setup the microcontroller system
|
* @brief Setup the microcontroller system
|
||||||
@@ -81,9 +82,9 @@ void SystemInit(void) {
|
|||||||
#endif /* STM32F105xC */
|
#endif /* STM32F105xC */
|
||||||
|
|
||||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||||
#ifdef DATA_IN_ExtSRAM
|
#ifdef DATA_IN_ExtSRAM
|
||||||
SystemInit_ExtMemCtl();
|
SystemInit_ExtMemCtl();
|
||||||
#endif /* DATA_IN_ExtSRAM */
|
#endif /* DATA_IN_ExtSRAM */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VECT_TAB_SRAM
|
#ifdef VECT_TAB_SRAM
|
||||||
@@ -166,9 +167,9 @@ void SystemCoreClockUpdate(void) {
|
|||||||
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
||||||
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
||||||
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
||||||
#else
|
#else
|
||||||
/* HSE selected as PLL clock entry */
|
/* HSE selected as PLL clock entry */
|
||||||
if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t) RESET) {/* HSE oscillator clock divided by 2 */
|
if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) { /* HSE oscillator clock divided by 2 */
|
||||||
SystemCoreClock = (HSE_VALUE >> 1U) * pllmull;
|
SystemCoreClock = (HSE_VALUE >> 1U) * pllmull;
|
||||||
} else {
|
} else {
|
||||||
SystemCoreClock = HSE_VALUE * pllmull;
|
SystemCoreClock = HSE_VALUE * pllmull;
|
||||||
@@ -178,34 +179,25 @@ void SystemCoreClockUpdate(void) {
|
|||||||
#else
|
#else
|
||||||
pllmull = pllmull >> 18U;
|
pllmull = pllmull >> 18U;
|
||||||
|
|
||||||
if (pllmull != 0x0DU)
|
if (pllmull != 0x0DU) {
|
||||||
{
|
|
||||||
pllmull += 2U;
|
pllmull += 2U;
|
||||||
}
|
} else { /* PLL multiplication factor = PLL input clock * 6.5 */
|
||||||
else
|
|
||||||
{ /* PLL multiplication factor = PLL input clock * 6.5 */
|
|
||||||
pllmull = 13U / 2U;
|
pllmull = 13U / 2U;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pllsource == 0x00U)
|
if (pllsource == 0x00U) {
|
||||||
{
|
|
||||||
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
|
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
|
||||||
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
|
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
|
||||||
}
|
} else { /* PREDIV1 selected as PLL clock entry */
|
||||||
else
|
|
||||||
{/* PREDIV1 selected as PLL clock entry */
|
|
||||||
|
|
||||||
/* Get PREDIV1 clock source and division factor */
|
/* Get PREDIV1 clock source and division factor */
|
||||||
prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
|
prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
|
||||||
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
||||||
|
|
||||||
if (prediv1source == 0U)
|
if (prediv1source == 0U) {
|
||||||
{
|
|
||||||
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
||||||
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
||||||
}
|
} else { /* PLL2 clock selected as PREDIV1 clock entry */
|
||||||
else
|
|
||||||
{/* PLL2 clock selected as PREDIV1 clock entry */
|
|
||||||
|
|
||||||
/* Get PREDIV2 division factor and PLL2 multiplication factor */
|
/* Get PREDIV2 division factor and PLL2 multiplication factor */
|
||||||
prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U;
|
prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U;
|
||||||
@@ -245,8 +237,7 @@ void SystemCoreClockUpdate(void) {
|
|||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void SystemInit_ExtMemCtl(void)
|
void SystemInit_ExtMemCtl(void) {
|
||||||
{
|
|
||||||
__IO uint32_t tmpreg;
|
__IO uint32_t tmpreg;
|
||||||
/*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
|
/*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
|
||||||
required, then adjust the Register Addresses */
|
required, then adjust the Register Addresses */
|
||||||
@@ -265,11 +256,11 @@ void SystemInit_ExtMemCtl(void)
|
|||||||
|
|
||||||
(void)(tmpreg);
|
(void)(tmpreg);
|
||||||
|
|
||||||
/* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
|
/* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
|
||||||
/*---------------- SRAM Address lines configuration -------------------------*/
|
/*---------------- SRAM Address lines configuration -------------------------*/
|
||||||
/*---------------- NOE and NWE configuration --------------------------------*/
|
/*---------------- NOE and NWE configuration --------------------------------*/
|
||||||
/*---------------- NE3 configuration ----------------------------------------*/
|
/*---------------- NE3 configuration ----------------------------------------*/
|
||||||
/*---------------- NBL0, NBL1 configuration ---------------------------------*/
|
/*---------------- NBL0, NBL1 configuration ---------------------------------*/
|
||||||
|
|
||||||
GPIOD->CRL = 0x44BB44BBU;
|
GPIOD->CRL = 0x44BB44BBU;
|
||||||
GPIOD->CRH = 0xBBBBBBBBU;
|
GPIOD->CRH = 0xBBBBBBBBU;
|
||||||
@@ -283,8 +274,8 @@ void SystemInit_ExtMemCtl(void)
|
|||||||
GPIOG->CRL = 0x44BBBBBBU;
|
GPIOG->CRL = 0x44BBBBBBU;
|
||||||
GPIOG->CRH = 0x444B4B44U;
|
GPIOG->CRH = 0x444B4B44U;
|
||||||
|
|
||||||
/*---------------- FSMC Configuration ---------------------------------------*/
|
/*---------------- FSMC Configuration ---------------------------------------*/
|
||||||
/*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
|
/*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
|
||||||
|
|
||||||
FSMC_Bank1->BTCR[4U] = 0x00001091U;
|
FSMC_Bank1->BTCR[4U] = 0x00001091U;
|
||||||
FSMC_Bank1->BTCR[5U] = 0x00110212U;
|
FSMC_Bank1->BTCR[5U] = 0x00110212U;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
bool BMA223::detect() {
|
bool BMA223::detect() {
|
||||||
if (FRToSI2C::probe(BMA223_ADDRESS)) {
|
if (FRToSI2C::probe(BMA223_ADDRESS)) {
|
||||||
//Read chip id to ensure its not an address collision
|
// Read chip id to ensure its not an address collision
|
||||||
uint8_t id = 0;
|
uint8_t id = 0;
|
||||||
if (FRToSI2C::Mem_Read(BMA223_ADDRESS, BMA223_BGW_CHIPID, &id, 1)) {
|
if (FRToSI2C::Mem_Read(BMA223_ADDRESS, BMA223_BGW_CHIPID, &id, 1)) {
|
||||||
return id == 0b11111000;
|
return id == 0b11111000;
|
||||||
@@ -20,45 +20,44 @@ bool BMA223::detect() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const FRToSI2C::I2C_REG i2c_registers[] = { //
|
static const FRToSI2C::I2C_REG i2c_registers[] = {
|
||||||
//
|
//
|
||||||
{ BMA223_PMU_RANGE, 0b00000011, 0 }, //2G range
|
//
|
||||||
{ BMA223_PMU_BW, 0b00001101, 0 }, //250Hz filter
|
{BMA223_PMU_RANGE, 0b00000011, 0}, // 2G range
|
||||||
{ BMA223_PMU_LPW, 0b00000000, 0 }, //Full power
|
{BMA223_PMU_BW, 0b00001101, 0}, // 250Hz filter
|
||||||
{ BMA223_ACCD_HBW, 0b00000000, 0 }, //filtered data out
|
{BMA223_PMU_LPW, 0b00000000, 0}, // Full power
|
||||||
{ BMA223_INT_OUT_CTRL, 0b00001010, 0 }, //interrupt active low and OD to get it hi-z
|
{BMA223_ACCD_HBW, 0b00000000, 0}, // filtered data out
|
||||||
{ BMA223_INT_RST_LATCH, 0b10000000, 0 }, //interrupt active low and OD to get it hi-z
|
{BMA223_INT_OUT_CTRL, 0b00001010, 0}, // interrupt active low and OD to get it hi-z
|
||||||
{ BMA223_INT_EN_0, 0b01000000, 0 }, //Enable orientation
|
{BMA223_INT_RST_LATCH, 0b10000000, 0}, // interrupt active low and OD to get it hi-z
|
||||||
{ BMA223_INT_A, 0b00100111, 0 }, //Setup orientation detection
|
{BMA223_INT_EN_0, 0b01000000, 0}, // Enable orientation
|
||||||
|
{BMA223_INT_A, 0b00100111, 0}, // Setup orientation detection
|
||||||
|
|
||||||
//
|
//
|
||||||
};
|
};
|
||||||
bool BMA223::initalize() {
|
bool BMA223::initalize() {
|
||||||
//Setup acceleration readings
|
// Setup acceleration readings
|
||||||
//2G range
|
// 2G range
|
||||||
//bandwidth = 250Hz
|
// bandwidth = 250Hz
|
||||||
//High pass filter on (Slow compensation)
|
// High pass filter on (Slow compensation)
|
||||||
//Turn off IRQ output pins
|
// Turn off IRQ output pins
|
||||||
//Orientation recognition in symmetrical mode
|
// Orientation recognition in symmetrical mode
|
||||||
// Hysteresis is set to ~ 16 counts
|
// Hysteresis is set to ~ 16 counts
|
||||||
//Theta blocking is set to 0b10
|
// Theta blocking is set to 0b10
|
||||||
|
|
||||||
return FRToSI2C::writeRegistersBulk(BMA223_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
return FRToSI2C::writeRegistersBulk(BMA223_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BMA223::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
void BMA223::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||||
//The BMA is odd in that its output data width is only 8 bits
|
// The BMA is odd in that its output data width is only 8 bits
|
||||||
//And yet there are MSB and LSB registers _sigh_.
|
// And yet there are MSB and LSB registers _sigh_.
|
||||||
uint8_t sensorData[6] = { 0, 0, 0, 0, 0, 0 };
|
uint8_t sensorData[6] = {0, 0, 0, 0, 0, 0};
|
||||||
|
|
||||||
if (FRToSI2C::Mem_Read(BMA223_ADDRESS, BMA223_ACCD_X_LSB, sensorData, 6) == false) {
|
if (FRToSI2C::Mem_Read(BMA223_ADDRESS, BMA223_ACCD_X_LSB, sensorData, 6) == false) {
|
||||||
x = y = z = 0;
|
x = y = z = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Shift 6 to make its range ~= the other accelerometers
|
// Shift 6 to make its range ~= the other accelerometers
|
||||||
x = sensorData[1] << 6;
|
x = sensorData[1] << 6;
|
||||||
y = sensorData[3] << 6;
|
y = sensorData[3] << 6;
|
||||||
z = sensorData[5] << 6;
|
z = sensorData[5] << 6;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
* Created on: 29 May 2020
|
* Created on: 29 May 2020
|
||||||
* Author: Ralim
|
* Author: Ralim
|
||||||
*/
|
*/
|
||||||
#include <Buttons.hpp>
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
|
||||||
#include "gui.hpp"
|
#include "gui.hpp"
|
||||||
|
#include "task.h"
|
||||||
|
#include <Buttons.hpp>
|
||||||
uint32_t lastButtonTime = 0;
|
uint32_t lastButtonTime = 0;
|
||||||
|
|
||||||
ButtonState getButtonState() {
|
ButtonState getButtonState() {
|
||||||
|
|||||||
@@ -6,15 +6,15 @@
|
|||||||
*/
|
*/
|
||||||
#include "Model_Config.h"
|
#include "Model_Config.h"
|
||||||
#ifdef POW_PD
|
#ifdef POW_PD
|
||||||
#include <fusbpd.h>
|
|
||||||
#include <pd.h>
|
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "I2CBB.hpp"
|
#include "I2CBB.hpp"
|
||||||
#include "fusb302b.h"
|
#include "fusb302b.h"
|
||||||
|
#include "int_n.h"
|
||||||
#include "policy_engine.h"
|
#include "policy_engine.h"
|
||||||
#include "protocol_rx.h"
|
#include "protocol_rx.h"
|
||||||
#include "protocol_tx.h"
|
#include "protocol_tx.h"
|
||||||
#include "int_n.h"
|
#include <fusbpd.h>
|
||||||
|
#include <pd.h>
|
||||||
|
|
||||||
void fusb302_start_processing() {
|
void fusb302_start_processing() {
|
||||||
/* Initialize the FUSB302B */
|
/* Initialize the FUSB302B */
|
||||||
|
|||||||
@@ -16,16 +16,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "int_n.h"
|
#include "int_n.h"
|
||||||
#include "fusbpd.h"
|
#include "BSP.h"
|
||||||
#include <pd.h>
|
|
||||||
#include "fusb302b.h"
|
#include "fusb302b.h"
|
||||||
#include "protocol_rx.h"
|
#include "fusbpd.h"
|
||||||
#include "protocol_tx.h"
|
|
||||||
#include "policy_engine.h"
|
#include "policy_engine.h"
|
||||||
#include "protocol_rx.h"
|
#include "protocol_rx.h"
|
||||||
#include "protocol_tx.h"
|
#include "protocol_tx.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "BSP.h"
|
#include <pd.h>
|
||||||
|
|
||||||
osThreadId InterruptHandler::TaskHandle = NULL;
|
osThreadId InterruptHandler::TaskHandle = NULL;
|
||||||
uint32_t InterruptHandler::TaskBuffer[InterruptHandler::TaskStackSize];
|
uint32_t InterruptHandler::TaskBuffer[InterruptHandler::TaskStackSize];
|
||||||
@@ -37,12 +35,12 @@ void InterruptHandler::init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InterruptHandler::Thread(const void *arg) {
|
void InterruptHandler::Thread(const void *arg) {
|
||||||
(void) arg;
|
(void)arg;
|
||||||
union fusb_status status;
|
union fusb_status status;
|
||||||
while (true) {
|
while (true) {
|
||||||
/* If the INT_N line is low */
|
/* If the INT_N line is low */
|
||||||
if (xTaskNotifyWait(0x00, 0x0F, NULL, PolicyEngine::setupCompleteOrTimedOut() ? 1000 : 10) == pdPASS) {
|
if (xTaskNotifyWait(0x00, 0x0F, NULL, PolicyEngine::setupCompleteOrTimedOut() ? 1000 : 10) == pdPASS) {
|
||||||
//delay slightly so we catch the crc with better timing
|
// delay slightly so we catch the crc with better timing
|
||||||
osDelay(1);
|
osDelay(1);
|
||||||
}
|
}
|
||||||
/* Read the FUSB302B status and interrupt registers */
|
/* Read the FUSB302B status and interrupt registers */
|
||||||
@@ -57,7 +55,7 @@ void InterruptHandler::Thread(const void *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If the I_GCRCSENT flag is set, tell the Protocol RX thread */
|
/* If the I_GCRCSENT flag is set, tell the Protocol RX thread */
|
||||||
//This means a message was recieved with a good CRC
|
// This means a message was recieved with a good CRC
|
||||||
if (status.interruptb & FUSB_INTERRUPTB_I_GCRCSENT) {
|
if (status.interruptb & FUSB_INTERRUPTB_I_GCRCSENT) {
|
||||||
ProtocolReceive::notify(PDB_EVT_PRLRX_I_GCRCSENT);
|
ProtocolReceive::notify(PDB_EVT_PRLRX_I_GCRCSENT);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "policy_engine.h"
|
#include "policy_engine.h"
|
||||||
#include <stdbool.h>
|
|
||||||
#include "int_n.h"
|
|
||||||
#include <pd.h>
|
|
||||||
#include "protocol_tx.h"
|
|
||||||
#include "fusb302b.h"
|
#include "fusb302b.h"
|
||||||
|
#include "int_n.h"
|
||||||
|
#include "protocol_tx.h"
|
||||||
|
#include <pd.h>
|
||||||
|
#include <stdbool.h>
|
||||||
bool PolicyEngine::pdNegotiationComplete;
|
bool PolicyEngine::pdNegotiationComplete;
|
||||||
int PolicyEngine::current_voltage_mv;
|
int PolicyEngine::current_voltage_mv;
|
||||||
int PolicyEngine::_requested_voltage;
|
int PolicyEngine::_requested_voltage;
|
||||||
@@ -39,17 +39,14 @@ union pd_msg PolicyEngine::tempMessage;
|
|||||||
union pd_msg PolicyEngine::_last_dpm_request;
|
union pd_msg PolicyEngine::_last_dpm_request;
|
||||||
PolicyEngine::policy_engine_state PolicyEngine::state = PESinkStartup;
|
PolicyEngine::policy_engine_state PolicyEngine::state = PESinkStartup;
|
||||||
StaticQueue_t PolicyEngine::xStaticQueue;
|
StaticQueue_t PolicyEngine::xStaticQueue;
|
||||||
uint8_t PolicyEngine::ucQueueStorageArea[PDB_MSG_POOL_SIZE
|
uint8_t PolicyEngine::ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)];
|
||||||
* sizeof(union pd_msg)];
|
|
||||||
QueueHandle_t PolicyEngine::messagesWaiting = NULL;
|
QueueHandle_t PolicyEngine::messagesWaiting = NULL;
|
||||||
EventGroupHandle_t PolicyEngine::xEventGroupHandle = NULL;
|
EventGroupHandle_t PolicyEngine::xEventGroupHandle = NULL;
|
||||||
StaticEventGroup_t PolicyEngine::xCreatedEventGroup;
|
StaticEventGroup_t PolicyEngine::xCreatedEventGroup;
|
||||||
void PolicyEngine::init() {
|
void PolicyEngine::init() {
|
||||||
messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE,
|
messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE, sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
|
||||||
sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
|
// Create static thread at PDB_PRIO_PE priority
|
||||||
//Create static thread at PDB_PRIO_PE priority
|
osThreadStaticDef(PolEng, pe_task, PDB_PRIO_PE, 0, TaskStackSize, TaskBuffer, &TaskControlBlock);
|
||||||
osThreadStaticDef(PolEng, pe_task, PDB_PRIO_PE, 0, TaskStackSize,
|
|
||||||
TaskBuffer, &TaskControlBlock);
|
|
||||||
TaskHandle = osThreadCreate(osThread(PolEng), NULL);
|
TaskHandle = osThreadCreate(osThread(PolEng), NULL);
|
||||||
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
||||||
}
|
}
|
||||||
@@ -61,8 +58,8 @@ void PolicyEngine::notify(uint32_t notification) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PolicyEngine::pe_task(const void *arg) {
|
void PolicyEngine::pe_task(const void *arg) {
|
||||||
(void) arg;
|
(void)arg;
|
||||||
//Internal thread loop
|
// Internal thread loop
|
||||||
hdr_template = PD_DATAROLE_UFP | PD_POWERROLE_SINK;
|
hdr_template = PD_DATAROLE_UFP | PD_POWERROLE_SINK;
|
||||||
/* Initialize the old_tcc_match */
|
/* Initialize the old_tcc_match */
|
||||||
_old_tcc_match = -1;
|
_old_tcc_match = -1;
|
||||||
@@ -72,7 +69,7 @@ void PolicyEngine::pe_task(const void *arg) {
|
|||||||
_last_pps = 8;
|
_last_pps = 8;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
//Loop based on state
|
// Loop based on state
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
|
||||||
case PESinkStartup:
|
case PESinkStartup:
|
||||||
@@ -137,7 +134,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_startup() {
|
|||||||
/* We don't have an explicit contract currently */
|
/* We don't have an explicit contract currently */
|
||||||
_explicit_contract = false;
|
_explicit_contract = false;
|
||||||
|
|
||||||
//If desired could send an alert that PD is starting
|
// If desired could send an alert that PD is starting
|
||||||
|
|
||||||
/* No need to reset the protocol layer here. There are two ways into this
|
/* No need to reset the protocol layer here. There are two ways into this
|
||||||
* state: startup and exiting hard reset. On startup, the protocol layer
|
* state: startup and exiting hard reset. On startup, the protocol layer
|
||||||
@@ -161,9 +158,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_wait_cap() {
|
|||||||
if (readMessage()) {
|
if (readMessage()) {
|
||||||
evt = PDB_EVT_PE_MSG_RX_PEND;
|
evt = PDB_EVT_PE_MSG_RX_PEND;
|
||||||
} else {
|
} else {
|
||||||
evt = waitForEvent(
|
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_RESET,
|
||||||
PDB_EVT_PE_MSG_RX | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_RESET,
|
// Wait for cap timeout
|
||||||
//Wait for cap timeout
|
|
||||||
PD_T_TYPEC_SINK_WAIT_CAP);
|
PD_T_TYPEC_SINK_WAIT_CAP);
|
||||||
}
|
}
|
||||||
/* If we timed out waiting for Source_Capabilities, send a hard reset */
|
/* If we timed out waiting for Source_Capabilities, send a hard reset */
|
||||||
@@ -184,8 +180,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_wait_cap() {
|
|||||||
/* Get the message */
|
/* Get the message */
|
||||||
while ((evt & PDB_EVT_PE_MSG_RX_PEND) || readMessage() == true) {
|
while ((evt & PDB_EVT_PE_MSG_RX_PEND) || readMessage() == true) {
|
||||||
/* If we got a Source_Capabilities message, read it. */
|
/* If we got a Source_Capabilities message, read it. */
|
||||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES
|
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) > 0) {
|
|
||||||
/* First, determine what PD revision we're using */
|
/* First, determine what PD revision we're using */
|
||||||
if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_1_0) {
|
if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_1_0) {
|
||||||
/* If the other end is using at least version 3.0, we'll
|
/* If the other end is using at least version 3.0, we'll
|
||||||
@@ -203,8 +198,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_wait_cap() {
|
|||||||
}
|
}
|
||||||
evt = 0;
|
evt = 0;
|
||||||
}
|
}
|
||||||
return PESinkWaitCap; //wait for more messages?
|
return PESinkWaitCap; // wait for more messages?
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we failed to get a message, send a hard reset */
|
/* If we failed to get a message, send a hard reset */
|
||||||
@@ -220,8 +214,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_eval_cap() {
|
|||||||
_pps_index = 8;
|
_pps_index = 8;
|
||||||
/* Search for the first PPS APDO */
|
/* Search for the first PPS APDO */
|
||||||
for (int8_t i = 0; i < PD_NUMOBJ_GET(&tempMessage); i++) {
|
for (int8_t i = 0; i < PD_NUMOBJ_GET(&tempMessage); i++) {
|
||||||
if ((tempMessage.obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED
|
if ((tempMessage.obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && (tempMessage.obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) {
|
||||||
&& (tempMessage.obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) {
|
|
||||||
_pps_index = i + 1;
|
_pps_index = i + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -242,13 +235,11 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_eval_cap() {
|
|||||||
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
||||||
|
|
||||||
/* Transmit the request */
|
/* Transmit the request */
|
||||||
waitForEvent(0xFFFF, 0); //clear pending
|
waitForEvent(0xFFFF, 0); // clear pending
|
||||||
ProtocolTransmit::pushMessage(&_last_dpm_request);
|
ProtocolTransmit::pushMessage(&_last_dpm_request);
|
||||||
//Send indication that there is a message pending
|
// Send indication that there is a message pending
|
||||||
ProtocolTransmit::notify(
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||||
eventmask_t evt = waitForEvent(
|
|
||||||
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET || evt == 0) {
|
if (evt & PDB_EVT_PE_RESET || evt == 0) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
@@ -259,8 +250,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for a response */
|
/* Wait for a response */
|
||||||
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
|
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE);
|
||||||
PD_T_SENDER_RESPONSE);
|
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
@@ -274,18 +264,14 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
|||||||
if (messageWaiting()) {
|
if (messageWaiting()) {
|
||||||
readMessage();
|
readMessage();
|
||||||
/* If the source accepted our request, wait for the new power */
|
/* If the source accepted our request, wait for the new power */
|
||||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT
|
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
|
|
||||||
return PESinkTransitionSink;
|
return PESinkTransitionSink;
|
||||||
/* If the message was a Soft_Reset, do the soft reset procedure */
|
/* If the message was a Soft_Reset, do the soft reset procedure */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
return PESinkSoftReset;
|
return PESinkSoftReset;
|
||||||
/* If the message was Wait or Reject */
|
/* If the message was Wait or Reject */
|
||||||
} else if ((PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REJECT
|
} else if ((PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REJECT || PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_WAIT) && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
|| PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_WAIT)
|
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
/* If we don't have an explicit contract, wait for capabilities */
|
/* If we don't have an explicit contract, wait for capabilities */
|
||||||
if (!_explicit_contract) {
|
if (!_explicit_contract) {
|
||||||
return PESinkWaitCap;
|
return PESinkWaitCap;
|
||||||
@@ -302,8 +288,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
|||||||
|
|
||||||
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_sink() {
|
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_sink() {
|
||||||
/* Wait for the PS_RDY message */
|
/* Wait for the PS_RDY message */
|
||||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
|
eventmask_t evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_PS_TRANSITION);
|
||||||
PD_T_PS_TRANSITION);
|
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
@@ -317,8 +302,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_sink() {
|
|||||||
if (messageWaiting()) {
|
if (messageWaiting()) {
|
||||||
readMessage();
|
readMessage();
|
||||||
/* If we got a PS_RDY, handle it */
|
/* If we got a PS_RDY, handle it */
|
||||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PS_RDY
|
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PS_RDY && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
/* We just finished negotiating an explicit contract */
|
/* We just finished negotiating an explicit contract */
|
||||||
_explicit_contract = true;
|
_explicit_contract = true;
|
||||||
|
|
||||||
@@ -344,8 +328,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() {
|
|||||||
eventmask_t evt;
|
eventmask_t evt;
|
||||||
|
|
||||||
/* Wait for an event */
|
/* Wait for an event */
|
||||||
evt = waitForEvent(
|
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP);
|
||||||
PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP);
|
|
||||||
|
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & PDB_EVT_PE_RESET) {
|
||||||
@@ -362,83 +345,65 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() {
|
|||||||
if (messageWaiting()) {
|
if (messageWaiting()) {
|
||||||
readMessage();
|
readMessage();
|
||||||
/* Ignore vendor-defined messages */
|
/* Ignore vendor-defined messages */
|
||||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VENDOR_DEFINED
|
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VENDOR_DEFINED && PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) > 0) {
|
|
||||||
|
|
||||||
return PESinkReady;
|
return PESinkReady;
|
||||||
/* Ignore Ping messages */
|
/* Ignore Ping messages */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PING
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PING && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
|
|
||||||
return PESinkReady;
|
return PESinkReady;
|
||||||
/* DR_Swap messages are not supported */
|
/* DR_Swap messages are not supported */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_DR_SWAP
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_DR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
|
|
||||||
return PESinkSendNotSupported;
|
return PESinkSendNotSupported;
|
||||||
/* Get_Source_Cap messages are not supported */
|
/* Get_Source_Cap messages are not supported */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SOURCE_CAP
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SOURCE_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
|
|
||||||
return PESinkSendNotSupported;
|
return PESinkSendNotSupported;
|
||||||
/* PR_Swap messages are not supported */
|
/* PR_Swap messages are not supported */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PR_SWAP
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
|
|
||||||
return PESinkSendNotSupported;
|
return PESinkSendNotSupported;
|
||||||
/* VCONN_Swap messages are not supported */
|
/* VCONN_Swap messages are not supported */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VCONN_SWAP
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VCONN_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
|
|
||||||
return PESinkSendNotSupported;
|
return PESinkSendNotSupported;
|
||||||
/* Request messages are not supported */
|
/* Request messages are not supported */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REQUEST
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REQUEST && PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) > 0) {
|
|
||||||
|
|
||||||
return PESinkSendNotSupported;
|
return PESinkSendNotSupported;
|
||||||
/* Sink_Capabilities messages are not supported */
|
/* Sink_Capabilities messages are not supported */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage)
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SINK_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||||
== PD_MSGTYPE_SINK_CAPABILITIES
|
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) > 0) {
|
|
||||||
|
|
||||||
return PESinkSendNotSupported;
|
return PESinkSendNotSupported;
|
||||||
/* Handle GotoMin messages */
|
/* Handle GotoMin messages */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GOTOMIN
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GOTOMIN && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
/* GiveBack is not supported */
|
/* GiveBack is not supported */
|
||||||
return PESinkSendNotSupported;
|
return PESinkSendNotSupported;
|
||||||
|
|
||||||
/* Evaluate new Source_Capabilities */
|
/* Evaluate new Source_Capabilities */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage)
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||||
== PD_MSGTYPE_SOURCE_CAPABILITIES
|
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) > 0) {
|
|
||||||
/* Don't free the message: we need to keep the
|
/* Don't free the message: we need to keep the
|
||||||
* Source_Capabilities message so we can evaluate it. */
|
* Source_Capabilities message so we can evaluate it. */
|
||||||
return PESinkEvalCap;
|
return PESinkEvalCap;
|
||||||
/* Give sink capabilities when asked */
|
/* Give sink capabilities when asked */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SINK_CAP
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SINK_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
|
|
||||||
return PESinkGiveSinkCap;
|
return PESinkGiveSinkCap;
|
||||||
/* If the message was a Soft_Reset, do the soft reset procedure */
|
/* If the message was a Soft_Reset, do the soft reset procedure */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
|
|
||||||
return PESinkSoftReset;
|
return PESinkSoftReset;
|
||||||
/* PD 3.0 messges */
|
/* PD 3.0 messges */
|
||||||
} else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) {
|
} else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) {
|
||||||
/* If the message is a multi-chunk extended message, let it
|
/* If the message is a multi-chunk extended message, let it
|
||||||
* time out. */
|
* time out. */
|
||||||
if ((tempMessage.hdr & PD_HDR_EXT)
|
if ((tempMessage.hdr & PD_HDR_EXT) && (PD_DATA_SIZE_GET(&tempMessage) > PD_MAX_EXT_MSG_LEGACY_LEN)) {
|
||||||
&& (PD_DATA_SIZE_GET(&tempMessage)
|
|
||||||
> PD_MAX_EXT_MSG_LEGACY_LEN)) {
|
|
||||||
|
|
||||||
return PESinkChunkReceived;
|
return PESinkChunkReceived;
|
||||||
/* Tell the DPM a message we sent got a response of
|
/* Tell the DPM a message we sent got a response of
|
||||||
* Not_Supported. */
|
* Not_Supported. */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage)
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_NOT_SUPPORTED && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
== PD_MSGTYPE_NOT_SUPPORTED
|
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
|
|
||||||
return PESinkNotSupportedReceived;
|
return PESinkNotSupportedReceived;
|
||||||
/* If we got an unknown message, send a soft reset */
|
/* If we got an unknown message, send a soft reset */
|
||||||
@@ -461,14 +426,11 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_get_source_cap() {
|
|||||||
/* Get a message object */
|
/* Get a message object */
|
||||||
union pd_msg *get_source_cap = &tempMessage;
|
union pd_msg *get_source_cap = &tempMessage;
|
||||||
/* Make a Get_Source_Cap message */
|
/* Make a Get_Source_Cap message */
|
||||||
get_source_cap->hdr = hdr_template | PD_MSGTYPE_GET_SOURCE_CAP
|
get_source_cap->hdr = hdr_template | PD_MSGTYPE_GET_SOURCE_CAP | PD_NUMOBJ(0);
|
||||||
| PD_NUMOBJ(0);
|
|
||||||
/* Transmit the Get_Source_Cap */
|
/* Transmit the Get_Source_Cap */
|
||||||
ProtocolTransmit::pushMessage(get_source_cap);
|
ProtocolTransmit::pushMessage(get_source_cap);
|
||||||
ProtocolTransmit::notify(
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||||
eventmask_t evt = waitForEvent(
|
|
||||||
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
|
||||||
/* Free the sent message */
|
/* Free the sent message */
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & PDB_EVT_PE_RESET) {
|
||||||
@@ -490,10 +452,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_give_sink_cap() {
|
|||||||
|
|
||||||
/* Transmit our capabilities */
|
/* Transmit our capabilities */
|
||||||
ProtocolTransmit::pushMessage(snk_cap);
|
ProtocolTransmit::pushMessage(snk_cap);
|
||||||
ProtocolTransmit::notify(
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||||
eventmask_t evt = waitForEvent(
|
|
||||||
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
|
||||||
|
|
||||||
/* Free the Sink_Capabilities message */
|
/* Free the Sink_Capabilities message */
|
||||||
|
|
||||||
@@ -515,8 +475,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_hard_reset() {
|
|||||||
if (_hard_reset_counter > PD_N_HARD_RESET_COUNT) {
|
if (_hard_reset_counter > PD_N_HARD_RESET_COUNT) {
|
||||||
return PESinkSourceUnresponsive;
|
return PESinkSourceUnresponsive;
|
||||||
}
|
}
|
||||||
//So, we could send a hardreset here; however that will cause a power cycle on the PSU end.. Which will then reset this MCU
|
// So, we could send a hardreset here; however that will cause a power cycle on the PSU end.. Which will then reset this MCU
|
||||||
//So therefore we went get anywhere :)
|
// So therefore we went get anywhere :)
|
||||||
/* Increment HardResetCounter */
|
/* Increment HardResetCounter */
|
||||||
_hard_reset_counter++;
|
_hard_reset_counter++;
|
||||||
|
|
||||||
@@ -546,10 +506,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_soft_reset() {
|
|||||||
accept.hdr = hdr_template | PD_MSGTYPE_ACCEPT | PD_NUMOBJ(0);
|
accept.hdr = hdr_template | PD_MSGTYPE_ACCEPT | PD_NUMOBJ(0);
|
||||||
/* Transmit the Accept */
|
/* Transmit the Accept */
|
||||||
ProtocolTransmit::pushMessage(&accept);
|
ProtocolTransmit::pushMessage(&accept);
|
||||||
ProtocolTransmit::notify(
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||||
eventmask_t evt = waitForEvent(
|
|
||||||
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
|
||||||
/* Free the sent message */
|
/* Free the sent message */
|
||||||
|
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
@@ -574,10 +532,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_soft_reset() {
|
|||||||
softrst->hdr = hdr_template | PD_MSGTYPE_SOFT_RESET | PD_NUMOBJ(0);
|
softrst->hdr = hdr_template | PD_MSGTYPE_SOFT_RESET | PD_NUMOBJ(0);
|
||||||
/* Transmit the soft reset */
|
/* Transmit the soft reset */
|
||||||
ProtocolTransmit::pushMessage(softrst);
|
ProtocolTransmit::pushMessage(softrst);
|
||||||
ProtocolTransmit::notify(
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||||
eventmask_t evt = waitForEvent(
|
|
||||||
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
@@ -588,8 +544,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_soft_reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for a response */
|
/* Wait for a response */
|
||||||
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
|
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE);
|
||||||
PD_T_SENDER_RESPONSE);
|
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
@@ -603,13 +558,11 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_soft_reset() {
|
|||||||
if (messageWaiting()) {
|
if (messageWaiting()) {
|
||||||
readMessage();
|
readMessage();
|
||||||
/* If the source accepted our soft reset, wait for capabilities. */
|
/* If the source accepted our soft reset, wait for capabilities. */
|
||||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT
|
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
|
|
||||||
return PESinkWaitCap;
|
return PESinkWaitCap;
|
||||||
/* If the message was a Soft_Reset, do the soft reset procedure */
|
/* If the message was a Soft_Reset, do the soft reset procedure */
|
||||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET
|
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
|
|
||||||
return PESinkSoftReset;
|
return PESinkSoftReset;
|
||||||
/* Otherwise, send a hard reset */
|
/* Otherwise, send a hard reset */
|
||||||
@@ -630,16 +583,13 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_not_supported() {
|
|||||||
not_supported->hdr = hdr_template | PD_MSGTYPE_REJECT | PD_NUMOBJ(0);
|
not_supported->hdr = hdr_template | PD_MSGTYPE_REJECT | PD_NUMOBJ(0);
|
||||||
} else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) {
|
} else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) {
|
||||||
/* Make a Not_Supported message */
|
/* Make a Not_Supported message */
|
||||||
not_supported->hdr = hdr_template | PD_MSGTYPE_NOT_SUPPORTED
|
not_supported->hdr = hdr_template | PD_MSGTYPE_NOT_SUPPORTED | PD_NUMOBJ(0);
|
||||||
| PD_NUMOBJ(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Transmit the message */
|
/* Transmit the message */
|
||||||
ProtocolTransmit::pushMessage(not_supported);
|
ProtocolTransmit::pushMessage(not_supported);
|
||||||
ProtocolTransmit::notify(
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||||
eventmask_t evt = waitForEvent(
|
|
||||||
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
|
||||||
|
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & PDB_EVT_PE_RESET) {
|
||||||
@@ -656,8 +606,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_not_supported() {
|
|||||||
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_chunk_received() {
|
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_chunk_received() {
|
||||||
|
|
||||||
/* Wait for tChunkingNotSupported */
|
/* Wait for tChunkingNotSupported */
|
||||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_RESET,
|
eventmask_t evt = waitForEvent(PDB_EVT_PE_RESET, PD_T_CHUNKING_NOT_SUPPORTED);
|
||||||
PD_T_CHUNKING_NOT_SUPPORTED);
|
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
@@ -674,19 +623,12 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_not_supported_received()
|
|||||||
}
|
}
|
||||||
|
|
||||||
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_source_unresponsive() {
|
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_source_unresponsive() {
|
||||||
//Sit and chill, as PD is not working
|
// Sit and chill, as PD is not working
|
||||||
osDelay(PD_T_PD_DEBOUNCE);
|
osDelay(PD_T_PD_DEBOUNCE);
|
||||||
|
|
||||||
return PESinkSourceUnresponsive;
|
return PESinkSourceUnresponsive;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t PolicyEngine::waitForEvent(uint32_t mask, TickType_t ticksToWait) {
|
uint32_t PolicyEngine::waitForEvent(uint32_t mask, TickType_t ticksToWait) { return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE, ticksToWait); }
|
||||||
return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE,
|
|
||||||
ticksToWait);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PolicyEngine::isPD3_0() {
|
|
||||||
return (hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
bool PolicyEngine::isPD3_0() { return (hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0; }
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
* Created on: 14 Jun 2020
|
* Created on: 14 Jun 2020
|
||||||
* Author: Ralim
|
* Author: Ralim
|
||||||
*/
|
*/
|
||||||
|
#include "BSP_PD.h"
|
||||||
#include "pd.h"
|
#include "pd.h"
|
||||||
#include "policy_engine.h"
|
#include "policy_engine.h"
|
||||||
#include "BSP_PD.h"
|
|
||||||
/* The current draw when the output is disabled */
|
/* The current draw when the output is disabled */
|
||||||
#define DPM_MIN_CURRENT PD_MA2PDI(50)
|
#define DPM_MIN_CURRENT PD_MA2PDI(50)
|
||||||
/*
|
/*
|
||||||
@@ -33,7 +33,7 @@ static int8_t dpm_get_range_fixed_pdo_index(const union pd_msg *caps) {
|
|||||||
* least our desired I */
|
* least our desired I */
|
||||||
uint16_t v = PD_PDO_SRC_FIXED_VOLTAGE_GET(caps->obj[i]);
|
uint16_t v = PD_PDO_SRC_FIXED_VOLTAGE_GET(caps->obj[i]);
|
||||||
if ((caps->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) {
|
if ((caps->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) {
|
||||||
if ( PD_PDO_SRC_FIXED_CURRENT_GET(caps->obj[i]) >= current) {
|
if (PD_PDO_SRC_FIXED_CURRENT_GET(caps->obj[i]) >= current) {
|
||||||
if (v >= PD_MV2PDV(voltagemin) && v <= PD_MV2PDV(voltagemax)) {
|
if (v >= PD_MV2PDV(voltagemin) && v <= PD_MV2PDV(voltagemax)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -43,48 +43,37 @@ static int8_t dpm_get_range_fixed_pdo_index(const union pd_msg *caps) {
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
bool PolicyEngine::pdbs_dpm_evaluate_capability(
|
bool PolicyEngine::pdbs_dpm_evaluate_capability(const union pd_msg *capabilities, union pd_msg *request) {
|
||||||
const union pd_msg *capabilities, union pd_msg *request) {
|
|
||||||
|
|
||||||
/* Get the number of PDOs */
|
/* Get the number of PDOs */
|
||||||
uint8_t numobj = PD_NUMOBJ_GET(capabilities);
|
uint8_t numobj = PD_NUMOBJ_GET(capabilities);
|
||||||
|
|
||||||
/* Get whether or not the power supply is constrained */
|
/* Get whether or not the power supply is constrained */
|
||||||
_unconstrained_power =
|
_unconstrained_power = capabilities->obj[0] & PD_PDO_SRC_FIXED_UNCONSTRAINED;
|
||||||
capabilities->obj[0] & PD_PDO_SRC_FIXED_UNCONSTRAINED;
|
|
||||||
|
|
||||||
/* Make sure we have configuration */
|
/* Make sure we have configuration */
|
||||||
/* Look at the PDOs to see if one matches our desires */
|
/* Look at the PDOs to see if one matches our desires */
|
||||||
//Look against USB_PD_Desired_Levels to select in order of preference
|
// Look against USB_PD_Desired_Levels to select in order of preference
|
||||||
for (uint8_t desiredLevel = 0; desiredLevel < USB_PD_Desired_Levels_Len;
|
for (uint8_t desiredLevel = 0; desiredLevel < USB_PD_Desired_Levels_Len; desiredLevel++) {
|
||||||
desiredLevel++) {
|
|
||||||
for (uint8_t i = 0; i < numobj; i++) {
|
for (uint8_t i = 0; i < numobj; i++) {
|
||||||
/* If we have a fixed PDO, its V equals our desired V, and its I is
|
/* If we have a fixed PDO, its V equals our desired V, and its I is
|
||||||
* at least our desired I */
|
* at least our desired I */
|
||||||
if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) {
|
if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) {
|
||||||
//This is a fixed PDO entry
|
// This is a fixed PDO entry
|
||||||
int voltage = PD_PDV2MV(
|
int voltage = PD_PDV2MV(PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities->obj[i]));
|
||||||
PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities->obj[i]));
|
int current = PD_PDO_SRC_FIXED_CURRENT_GET(capabilities->obj[i]);
|
||||||
int current = PD_PDO_SRC_FIXED_CURRENT_GET(
|
uint16_t desiredVoltage = USB_PD_Desired_Levels[(desiredLevel * 2) + 0];
|
||||||
capabilities->obj[i]);
|
uint16_t desiredminCurrent = USB_PD_Desired_Levels[(desiredLevel * 2) + 1];
|
||||||
uint16_t desiredVoltage = USB_PD_Desired_Levels[(desiredLevel
|
// As pd stores current in 10mA increments, divide by 10
|
||||||
* 2) + 0];
|
|
||||||
uint16_t desiredminCurrent = USB_PD_Desired_Levels[(desiredLevel
|
|
||||||
* 2) + 1];
|
|
||||||
//As pd stores current in 10mA increments, divide by 10
|
|
||||||
desiredminCurrent /= 10;
|
desiredminCurrent /= 10;
|
||||||
if (voltage == desiredVoltage) {
|
if (voltage == desiredVoltage) {
|
||||||
if (current >= desiredminCurrent) {
|
if (current >= desiredminCurrent) {
|
||||||
/* We got what we wanted, so build a request for that */
|
/* We got what we wanted, so build a request for that */
|
||||||
request->hdr = hdr_template | PD_MSGTYPE_REQUEST
|
request->hdr = hdr_template | PD_MSGTYPE_REQUEST | PD_NUMOBJ(1);
|
||||||
| PD_NUMOBJ(1);
|
|
||||||
|
|
||||||
/* GiveBack disabled */
|
/* GiveBack disabled */
|
||||||
request->obj[0] =
|
request->obj[0] = PD_RDO_FV_MAX_CURRENT_SET(current) | PD_RDO_FV_CURRENT_SET(current) | PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(i + 1);
|
||||||
PD_RDO_FV_MAX_CURRENT_SET(
|
// We support usb comms (ish)
|
||||||
current) | PD_RDO_FV_CURRENT_SET(current)
|
|
||||||
| PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(i + 1);
|
|
||||||
//We support usb comms (ish)
|
|
||||||
request->obj[0] |= PD_RDO_USB_COMMS;
|
request->obj[0] |= PD_RDO_USB_COMMS;
|
||||||
|
|
||||||
/* Update requested voltage */
|
/* Update requested voltage */
|
||||||
@@ -94,16 +83,12 @@ bool PolicyEngine::pdbs_dpm_evaluate_capability(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Nothing matched (or no configuration), so get 5 V at low current */
|
/* Nothing matched (or no configuration), so get 5 V at low current */
|
||||||
request->hdr = hdr_template | PD_MSGTYPE_REQUEST | PD_NUMOBJ(1);
|
request->hdr = hdr_template | PD_MSGTYPE_REQUEST | PD_NUMOBJ(1);
|
||||||
request->obj[0] =
|
request->obj[0] = PD_RDO_FV_MAX_CURRENT_SET(DPM_MIN_CURRENT) | PD_RDO_FV_CURRENT_SET(DPM_MIN_CURRENT) | PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(1);
|
||||||
PD_RDO_FV_MAX_CURRENT_SET(
|
|
||||||
DPM_MIN_CURRENT) | PD_RDO_FV_CURRENT_SET(DPM_MIN_CURRENT) | PD_RDO_NO_USB_SUSPEND
|
|
||||||
| PD_RDO_OBJPOS_SET(1);
|
|
||||||
/* If the output is enabled and we got here, it must be a capability
|
/* If the output is enabled and we got here, it must be a capability
|
||||||
* mismatch. */
|
* mismatch. */
|
||||||
if (pdNegotiationComplete) {
|
if (pdNegotiationComplete) {
|
||||||
@@ -124,18 +109,13 @@ void PolicyEngine::pdbs_dpm_get_sink_capability(union pd_msg *cap) {
|
|||||||
/* If we have no configuration or want something other than 5 V, add a PDO
|
/* If we have no configuration or want something other than 5 V, add a PDO
|
||||||
* for vSafe5V */
|
* for vSafe5V */
|
||||||
/* Minimum current, 5 V, and higher capability. */
|
/* Minimum current, 5 V, and higher capability. */
|
||||||
cap->obj[numobj++] =
|
cap->obj[numobj++] = PD_PDO_TYPE_FIXED | PD_PDO_SNK_FIXED_VOLTAGE_SET(PD_MV2PDV(5000)) | PD_PDO_SNK_FIXED_CURRENT_SET(DPM_MIN_CURRENT);
|
||||||
PD_PDO_TYPE_FIXED
|
|
||||||
| PD_PDO_SNK_FIXED_VOLTAGE_SET(
|
|
||||||
PD_MV2PDV(5000)) | PD_PDO_SNK_FIXED_CURRENT_SET(DPM_MIN_CURRENT);
|
|
||||||
|
|
||||||
/* Get the current we want */
|
/* Get the current we want */
|
||||||
uint16_t current = USB_PD_Desired_Levels[1] / 10; // In centi-amps
|
uint16_t current = USB_PD_Desired_Levels[1] / 10; // In centi-amps
|
||||||
uint16_t voltage = USB_PD_Desired_Levels[0]; // in mv
|
uint16_t voltage = USB_PD_Desired_Levels[0]; // in mv
|
||||||
/* Add a PDO for the desired power. */
|
/* Add a PDO for the desired power. */
|
||||||
cap->obj[numobj++] = PD_PDO_TYPE_FIXED
|
cap->obj[numobj++] = PD_PDO_TYPE_FIXED | PD_PDO_SNK_FIXED_VOLTAGE_SET(PD_MV2PDV(voltage)) | PD_PDO_SNK_FIXED_CURRENT_SET(current);
|
||||||
| PD_PDO_SNK_FIXED_VOLTAGE_SET(
|
|
||||||
PD_MV2PDV(voltage)) | PD_PDO_SNK_FIXED_CURRENT_SET(current);
|
|
||||||
|
|
||||||
/* Get the PDO from the voltage range */
|
/* Get the PDO from the voltage range */
|
||||||
int8_t i = dpm_get_range_fixed_pdo_index(cap);
|
int8_t i = dpm_get_range_fixed_pdo_index(cap);
|
||||||
@@ -152,20 +132,13 @@ void PolicyEngine::pdbs_dpm_get_sink_capability(union pd_msg *cap) {
|
|||||||
|
|
||||||
/* If the range PDO is a different voltage than the preferred
|
/* If the range PDO is a different voltage than the preferred
|
||||||
* voltage, add it to the array. */
|
* voltage, add it to the array. */
|
||||||
if (i
|
if (i > 0 && PD_PDO_SRC_FIXED_VOLTAGE_GET(cap->obj[i]) != PD_MV2PDV(voltage)) {
|
||||||
> 0&& PD_PDO_SRC_FIXED_VOLTAGE_GET(cap->obj[i]) != PD_MV2PDV(voltage)) {
|
cap->obj[numobj++] = PD_PDO_TYPE_FIXED | PD_PDO_SNK_FIXED_VOLTAGE_SET(PD_PDO_SRC_FIXED_VOLTAGE_GET(cap->obj[i])) | PD_PDO_SNK_FIXED_CURRENT_SET(PD_PDO_SRC_FIXED_CURRENT_GET(cap->obj[i]));
|
||||||
cap->obj[numobj++] =
|
|
||||||
PD_PDO_TYPE_FIXED
|
|
||||||
| PD_PDO_SNK_FIXED_VOLTAGE_SET(
|
|
||||||
PD_PDO_SRC_FIXED_VOLTAGE_GET(cap->obj[i])) | PD_PDO_SNK_FIXED_CURRENT_SET(
|
|
||||||
PD_PDO_SRC_FIXED_CURRENT_GET(cap->obj[i]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we have three PDOs at this point, make sure the last two are
|
/* If we have three PDOs at this point, make sure the last two are
|
||||||
* sorted by voltage. */
|
* sorted by voltage. */
|
||||||
if (numobj == 3
|
if (numobj == 3 && (cap->obj[1] & PD_PDO_SNK_FIXED_VOLTAGE) > (cap->obj[2] & PD_PDO_SNK_FIXED_VOLTAGE)) {
|
||||||
&& (cap->obj[1] & PD_PDO_SNK_FIXED_VOLTAGE)
|
|
||||||
> (cap->obj[2] & PD_PDO_SNK_FIXED_VOLTAGE)) {
|
|
||||||
cap->obj[1] ^= cap->obj[2];
|
cap->obj[1] ^= cap->obj[2];
|
||||||
cap->obj[2] ^= cap->obj[1];
|
cap->obj[2] ^= cap->obj[1];
|
||||||
cap->obj[1] ^= cap->obj[2];
|
cap->obj[1] ^= cap->obj[2];
|
||||||
@@ -183,13 +156,12 @@ void PolicyEngine::pdbs_dpm_get_sink_capability(union pd_msg *cap) {
|
|||||||
cap->hdr = hdr_template | PD_MSGTYPE_SINK_CAPABILITIES | PD_NUMOBJ(numobj);
|
cap->hdr = hdr_template | PD_MSGTYPE_SINK_CAPABILITIES | PD_NUMOBJ(numobj);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PolicyEngine::pdbs_dpm_evaluate_typec_current(
|
bool PolicyEngine::pdbs_dpm_evaluate_typec_current(enum fusb_typec_current tcc) {
|
||||||
enum fusb_typec_current tcc) {
|
(void)tcc;
|
||||||
(void) tcc;
|
// This is for evaluating 5V static current advertised by resistors
|
||||||
//This is for evaluating 5V static current advertised by resistors
|
|
||||||
/* We don't control the voltage anymore; it will always be 5 V. */
|
/* We don't control the voltage anymore; it will always be 5 V. */
|
||||||
current_voltage_mv = _requested_voltage = 5000;
|
current_voltage_mv = _requested_voltage = 5000;
|
||||||
//For the soldering iron we accept this as a fallback, but it sucks
|
// For the soldering iron we accept this as a fallback, but it sucks
|
||||||
pdNegotiationComplete = false;
|
pdNegotiationComplete = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -208,20 +180,14 @@ void PolicyEngine::pdbs_dpm_transition_requested() {
|
|||||||
pdNegotiationComplete = true;
|
pdNegotiationComplete = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PolicyEngine::handleMessage(union pd_msg *msg) {
|
void PolicyEngine::handleMessage(union pd_msg *msg) { xQueueSend(messagesWaiting, msg, 100); }
|
||||||
xQueueSend(messagesWaiting, msg, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PolicyEngine::messageWaiting() {
|
bool PolicyEngine::messageWaiting() { return uxQueueMessagesWaiting(messagesWaiting) > 0; }
|
||||||
return uxQueueMessagesWaiting(messagesWaiting) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PolicyEngine::readMessage() {
|
bool PolicyEngine::readMessage() { return xQueueReceive(messagesWaiting, &tempMessage, 0) == pdTRUE; }
|
||||||
return xQueueReceive(messagesWaiting, &tempMessage, 0) == pdTRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PolicyEngine::pdbs_dpm_transition_typec() {
|
void PolicyEngine::pdbs_dpm_transition_typec() {
|
||||||
//This means PD failed, so we either have a dump 5V only type C or a QC charger
|
// This means PD failed, so we either have a dump 5V only type C or a QC charger
|
||||||
//For now; treat this as failed neg
|
// For now; treat this as failed neg
|
||||||
pdNegotiationComplete = false;
|
pdNegotiationComplete = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,12 @@
|
|||||||
|
|
||||||
#include "protocol_rx.h"
|
#include "protocol_rx.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include "fusb302b.h"
|
||||||
#include "string.h"
|
|
||||||
#include <pd.h>
|
|
||||||
#include "policy_engine.h"
|
#include "policy_engine.h"
|
||||||
#include "protocol_tx.h"
|
#include "protocol_tx.h"
|
||||||
#include "fusb302b.h"
|
#include "string.h"
|
||||||
|
#include <pd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
osThreadId ProtocolReceive::TaskHandle = NULL;
|
osThreadId ProtocolReceive::TaskHandle = NULL;
|
||||||
EventGroupHandle_t ProtocolReceive::xEventGroupHandle = NULL;
|
EventGroupHandle_t ProtocolReceive::xEventGroupHandle = NULL;
|
||||||
StaticEventGroup_t ProtocolReceive::xCreatedEventGroup;
|
StaticEventGroup_t ProtocolReceive::xCreatedEventGroup;
|
||||||
@@ -37,8 +37,7 @@ uint8_t ProtocolReceive::_tx_messageidcounter;
|
|||||||
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_wait_phy() {
|
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_wait_phy() {
|
||||||
/* Wait for an event */
|
/* Wait for an event */
|
||||||
_rx_messageid = 0;
|
_rx_messageid = 0;
|
||||||
eventmask_t evt = waitForEvent(
|
eventmask_t evt = waitForEvent(PDB_EVT_PRLRX_RESET | PDB_EVT_PRLRX_I_GCRCSENT | PDB_EVT_PRLRX_I_RXPEND);
|
||||||
PDB_EVT_PRLRX_RESET | PDB_EVT_PRLRX_I_GCRCSENT | PDB_EVT_PRLRX_I_RXPEND);
|
|
||||||
|
|
||||||
/* If we got a reset event, reset */
|
/* If we got a reset event, reset */
|
||||||
if (evt & PDB_EVT_PRLRX_RESET) {
|
if (evt & PDB_EVT_PRLRX_RESET) {
|
||||||
@@ -54,15 +53,14 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_wait_phy() {
|
|||||||
/* Read the message */
|
/* Read the message */
|
||||||
fusb_read_message(_rx_message);
|
fusb_read_message(_rx_message);
|
||||||
/* If it's a Soft_Reset, go to the soft reset state */
|
/* If it's a Soft_Reset, go to the soft reset state */
|
||||||
if (PD_MSGTYPE_GET(_rx_message) == PD_MSGTYPE_SOFT_RESET
|
if (PD_MSGTYPE_GET(_rx_message) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(_rx_message) == 0) {
|
||||||
&& PD_NUMOBJ_GET(_rx_message) == 0) {
|
|
||||||
return PRLRxReset;
|
return PRLRxReset;
|
||||||
} else {
|
} else {
|
||||||
/* Otherwise, check the message ID */
|
/* Otherwise, check the message ID */
|
||||||
return PRLRxCheckMessageID;
|
return PRLRxCheckMessageID;
|
||||||
}
|
}
|
||||||
} else if (evt & PDB_EVT_PRLRX_I_RXPEND) {
|
} else if (evt & PDB_EVT_PRLRX_I_RXPEND) {
|
||||||
//There is an RX message pending that is not a Good CRC
|
// There is an RX message pending that is not a Good CRC
|
||||||
union pd_msg *_rx_message = &tempMessage;
|
union pd_msg *_rx_message = &tempMessage;
|
||||||
/* Read the message */
|
/* Read the message */
|
||||||
fusb_read_message(_rx_message);
|
fusb_read_message(_rx_message);
|
||||||
@@ -83,8 +81,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_reset() {
|
|||||||
_rx_messageid = -1;
|
_rx_messageid = -1;
|
||||||
|
|
||||||
/* TX transitions to its reset state */
|
/* TX transitions to its reset state */
|
||||||
ProtocolTransmit::notify(
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_RESET);
|
||||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_RESET);
|
|
||||||
taskYIELD();
|
taskYIELD();
|
||||||
|
|
||||||
/* If we got a RESET signal, reset the machine */
|
/* If we got a RESET signal, reset the machine */
|
||||||
@@ -101,17 +98,17 @@ volatile uint32_t rxCounter = 0;
|
|||||||
*/
|
*/
|
||||||
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_check_messageid() {
|
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_check_messageid() {
|
||||||
/* If we got a RESET signal, reset the machine */
|
/* If we got a RESET signal, reset the machine */
|
||||||
// if (waitForEvent(PDB_EVT_PRLRX_RESET, 0) == PDB_EVT_PRLRX_RESET) {
|
// if (waitForEvent(PDB_EVT_PRLRX_RESET, 0) == PDB_EVT_PRLRX_RESET) {
|
||||||
// return PRLRxWaitPHY;
|
// return PRLRxWaitPHY;
|
||||||
// }
|
// }
|
||||||
/* If the message has the stored ID, we've seen this message before. Free
|
/* If the message has the stored ID, we've seen this message before. Free
|
||||||
* it and don't pass it to the policy engine. */
|
* it and don't pass it to the policy engine. */
|
||||||
|
|
||||||
/* Otherwise, there's either no stored ID or this message has an ID we
|
/* Otherwise, there's either no stored ID or this message has an ID we
|
||||||
* haven't just seen. Transition to the Store_MessageID state. */
|
* haven't just seen. Transition to the Store_MessageID state. */
|
||||||
// if (PD_MESSAGEID_GET(&tempMessage) == _rx_messageid) {
|
// if (PD_MESSAGEID_GET(&tempMessage) == _rx_messageid) {
|
||||||
// return PRLRxWaitPHY;
|
// return PRLRxWaitPHY;
|
||||||
// } else
|
// } else
|
||||||
{
|
{
|
||||||
rxCounter++;
|
rxCounter++;
|
||||||
return PRLRxStoreMessageID;
|
return PRLRxStoreMessageID;
|
||||||
@@ -124,8 +121,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_check_messageid(
|
|||||||
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_store_messageid() {
|
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_store_messageid() {
|
||||||
/* Tell ProtocolTX to discard the message being transmitted */
|
/* Tell ProtocolTX to discard the message being transmitted */
|
||||||
|
|
||||||
ProtocolTransmit::notify(
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_DISCARD);
|
||||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_DISCARD);
|
|
||||||
|
|
||||||
/* Update the stored MessageID */
|
/* Update the stored MessageID */
|
||||||
_rx_messageid = PD_MESSAGEID_GET(&tempMessage);
|
_rx_messageid = PD_MESSAGEID_GET(&tempMessage);
|
||||||
@@ -141,14 +137,13 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_store_messageid(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolReceive::init() {
|
void ProtocolReceive::init() {
|
||||||
osThreadStaticDef(protRX, thread, PDB_PRIO_PRL, 0, TaskStackSize,
|
osThreadStaticDef(protRX, thread, PDB_PRIO_PRL, 0, TaskStackSize, TaskBuffer, &TaskControlBlock);
|
||||||
TaskBuffer, &TaskControlBlock);
|
|
||||||
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
||||||
TaskHandle = osThreadCreate(osThread(protRX), NULL);
|
TaskHandle = osThreadCreate(osThread(protRX), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolReceive::thread(const void *args) {
|
void ProtocolReceive::thread(const void *args) {
|
||||||
(void) args;
|
(void)args;
|
||||||
ProtocolReceive::protocol_rx_state state = PRLRxWaitPHY;
|
ProtocolReceive::protocol_rx_state state = PRLRxWaitPHY;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -182,8 +177,7 @@ void ProtocolReceive::notify(uint32_t notification) {
|
|||||||
|
|
||||||
uint32_t ProtocolReceive::waitForEvent(uint32_t mask, TickType_t ticksToWait) {
|
uint32_t ProtocolReceive::waitForEvent(uint32_t mask, TickType_t ticksToWait) {
|
||||||
if (xEventGroupHandle != NULL) {
|
if (xEventGroupHandle != NULL) {
|
||||||
return xEventGroupWaitBits(xEventGroupHandle, mask, mask,
|
return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE, ticksToWait);
|
||||||
pdFALSE, ticksToWait);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,19 +16,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "protocol_tx.h"
|
#include "protocol_tx.h"
|
||||||
#include <pd.h>
|
|
||||||
#include "policy_engine.h"
|
|
||||||
#include "protocol_rx.h"
|
|
||||||
#include "fusb302b.h"
|
#include "fusb302b.h"
|
||||||
#include "fusbpd.h"
|
#include "fusbpd.h"
|
||||||
|
#include "policy_engine.h"
|
||||||
|
#include "protocol_rx.h"
|
||||||
|
#include <pd.h>
|
||||||
|
|
||||||
osThreadId ProtocolTransmit::TaskHandle = NULL;
|
osThreadId ProtocolTransmit::TaskHandle = NULL;
|
||||||
uint32_t ProtocolTransmit::TaskBuffer[ProtocolTransmit::TaskStackSize];
|
uint32_t ProtocolTransmit::TaskBuffer[ProtocolTransmit::TaskStackSize];
|
||||||
osStaticThreadDef_t ProtocolTransmit::TaskControlBlock;
|
osStaticThreadDef_t ProtocolTransmit::TaskControlBlock;
|
||||||
StaticQueue_t ProtocolTransmit::xStaticQueue;
|
StaticQueue_t ProtocolTransmit::xStaticQueue;
|
||||||
bool ProtocolTransmit::messageSending = false;
|
bool ProtocolTransmit::messageSending = false;
|
||||||
uint8_t ProtocolTransmit::ucQueueStorageArea[PDB_MSG_POOL_SIZE
|
uint8_t ProtocolTransmit::ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)];
|
||||||
* sizeof(union pd_msg)];
|
|
||||||
QueueHandle_t ProtocolTransmit::messagesWaiting = NULL;
|
QueueHandle_t ProtocolTransmit::messagesWaiting = NULL;
|
||||||
uint8_t ProtocolTransmit::_tx_messageidcounter;
|
uint8_t ProtocolTransmit::_tx_messageidcounter;
|
||||||
union pd_msg ProtocolTransmit::temp_msg;
|
union pd_msg ProtocolTransmit::temp_msg;
|
||||||
@@ -45,10 +44,10 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_phy_reset() {
|
|||||||
* we failed to send it */
|
* we failed to send it */
|
||||||
if (messagePending()) {
|
if (messagePending()) {
|
||||||
/* Tell the policy engine that we failed */
|
/* Tell the policy engine that we failed */
|
||||||
PolicyEngine::notify( PDB_EVT_PE_TX_ERR);
|
PolicyEngine::notify(PDB_EVT_PE_TX_ERR);
|
||||||
/* Finish failing to send the message */
|
/* Finish failing to send the message */
|
||||||
while (messagePending()) {
|
while (messagePending()) {
|
||||||
getMessage(); //Discard
|
getMessage(); // Discard
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,23 +60,19 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_phy_reset() {
|
|||||||
*/
|
*/
|
||||||
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_message() {
|
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_message() {
|
||||||
/* Wait for an event */
|
/* Wait for an event */
|
||||||
ProtocolTransmit::Notifications evt = waitForEvent(
|
ProtocolTransmit::Notifications evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PRLTX_RESET | (uint32_t)Notifications::PDB_EVT_PRLTX_DISCARD | (uint32_t)Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||||
(uint32_t) Notifications::PDB_EVT_PRLTX_RESET
|
|
||||||
| (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD
|
|
||||||
| (uint32_t) Notifications::PDB_EVT_PRLTX_MSG_TX);
|
|
||||||
|
|
||||||
if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_RESET) {
|
if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_RESET) {
|
||||||
return PRLTxPHYReset;
|
return PRLTxPHYReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the policy engine is trying to send a message */
|
/* If the policy engine is trying to send a message */
|
||||||
if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_MSG_TX) {
|
if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_MSG_TX) {
|
||||||
/* Get the message */
|
/* Get the message */
|
||||||
getMessage();
|
getMessage();
|
||||||
|
|
||||||
/* If it's a Soft_Reset, reset the TX layer first */
|
/* If it's a Soft_Reset, reset the TX layer first */
|
||||||
if (PD_MSGTYPE_GET(&temp_msg) == PD_MSGTYPE_SOFT_RESET
|
if (PD_MSGTYPE_GET(&temp_msg) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&(temp_msg)) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&(temp_msg)) == 0) {
|
|
||||||
return PRLTxReset;
|
return PRLTxReset;
|
||||||
/* Otherwise, just send the message */
|
/* Otherwise, just send the message */
|
||||||
} else {
|
} else {
|
||||||
@@ -94,7 +89,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_reset() {
|
|||||||
_tx_messageidcounter = 0;
|
_tx_messageidcounter = 0;
|
||||||
|
|
||||||
/* Tell the Protocol RX thread to reset */
|
/* Tell the Protocol RX thread to reset */
|
||||||
ProtocolReceive::notify( PDB_EVT_PRLRX_RESET);
|
ProtocolReceive::notify(PDB_EVT_PRLRX_RESET);
|
||||||
taskYIELD();
|
taskYIELD();
|
||||||
|
|
||||||
return PRLTxConstructMessage;
|
return PRLTxConstructMessage;
|
||||||
@@ -109,17 +104,17 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_mess
|
|||||||
temp_msg.hdr |= (_tx_messageidcounter % 8) << PD_HDR_MESSAGEID_SHIFT;
|
temp_msg.hdr |= (_tx_messageidcounter % 8) << PD_HDR_MESSAGEID_SHIFT;
|
||||||
|
|
||||||
/* PD 3.0 collision avoidance */
|
/* PD 3.0 collision avoidance */
|
||||||
// if (PolicyEngine::isPD3_0()) {
|
// if (PolicyEngine::isPD3_0()) {
|
||||||
// /* If we're starting an AMS, wait for permission to transmit */
|
// /* If we're starting an AMS, wait for permission to transmit */
|
||||||
// evt = waitForEvent((uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS,
|
// evt = waitForEvent((uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS,
|
||||||
// 0);
|
// 0);
|
||||||
// if ((uint32_t) evt
|
// if ((uint32_t) evt
|
||||||
// & (uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS) {
|
// & (uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS) {
|
||||||
// while (fusb_get_typec_current() != fusb_sink_tx_ok) {
|
// while (fusb_get_typec_current() != fusb_sink_tx_ok) {
|
||||||
// osDelay(1);
|
// osDelay(1);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
messageSending = true;
|
messageSending = true;
|
||||||
/* Send the message to the PHY */
|
/* Send the message to the PHY */
|
||||||
fusb_send_message(&temp_msg);
|
fusb_send_message(&temp_msg);
|
||||||
@@ -133,25 +128,22 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_mess
|
|||||||
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_response() {
|
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_response() {
|
||||||
/* Wait for an event. There is no need to run CRCReceiveTimer, since the
|
/* Wait for an event. There is no need to run CRCReceiveTimer, since the
|
||||||
* FUSB302B handles that as part of its retry mechanism. */
|
* FUSB302B handles that as part of its retry mechanism. */
|
||||||
ProtocolTransmit::Notifications evt = waitForEvent(
|
ProtocolTransmit::Notifications evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PRLTX_RESET | (uint32_t)Notifications::PDB_EVT_PRLTX_DISCARD | (uint32_t)Notifications::PDB_EVT_PRLTX_I_TXSENT
|
||||||
(uint32_t) Notifications::PDB_EVT_PRLTX_RESET
|
| (uint32_t)Notifications::PDB_EVT_PRLTX_I_RETRYFAIL);
|
||||||
| (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD
|
|
||||||
| (uint32_t) Notifications::PDB_EVT_PRLTX_I_TXSENT
|
|
||||||
| (uint32_t) Notifications::PDB_EVT_PRLTX_I_RETRYFAIL);
|
|
||||||
|
|
||||||
if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_RESET) {
|
if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_RESET) {
|
||||||
return PRLTxPHYReset;
|
return PRLTxPHYReset;
|
||||||
}
|
}
|
||||||
if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD) {
|
if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_DISCARD) {
|
||||||
return PRLTxDiscardMessage;
|
return PRLTxDiscardMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the message was sent successfully */
|
/* If the message was sent successfully */
|
||||||
if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_I_TXSENT) {
|
if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_I_TXSENT) {
|
||||||
return PRLTxMatchMessageID;
|
return PRLTxMatchMessageID;
|
||||||
}
|
}
|
||||||
/* If the message failed to be sent */
|
/* If the message failed to be sent */
|
||||||
if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_I_RETRYFAIL) {
|
if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_I_RETRYFAIL) {
|
||||||
return PRLTxTransmissionError;
|
return PRLTxTransmissionError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,9 +161,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_match_messagei
|
|||||||
fusb_read_message(&goodcrc);
|
fusb_read_message(&goodcrc);
|
||||||
|
|
||||||
/* Check that the message is correct */
|
/* Check that the message is correct */
|
||||||
if (PD_MSGTYPE_GET(&goodcrc) == PD_MSGTYPE_GOODCRC
|
if (PD_MSGTYPE_GET(&goodcrc) == PD_MSGTYPE_GOODCRC && PD_NUMOBJ_GET(&goodcrc) == 0 && PD_MESSAGEID_GET(&goodcrc) == _tx_messageidcounter) {
|
||||||
&& PD_NUMOBJ_GET(&goodcrc) == 0
|
|
||||||
&& PD_MESSAGEID_GET(&goodcrc) == _tx_messageidcounter) {
|
|
||||||
return PRLTxMessageSent;
|
return PRLTxMessageSent;
|
||||||
} else {
|
} else {
|
||||||
return PRLTxTransmissionError;
|
return PRLTxTransmissionError;
|
||||||
@@ -183,7 +173,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_transmission_e
|
|||||||
_tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
|
_tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
|
||||||
|
|
||||||
/* Tell the policy engine that we failed */
|
/* Tell the policy engine that we failed */
|
||||||
PolicyEngine::notify( PDB_EVT_PE_TX_ERR);
|
PolicyEngine::notify(PDB_EVT_PE_TX_ERR);
|
||||||
|
|
||||||
return PRLTxWaitMessage;
|
return PRLTxWaitMessage;
|
||||||
}
|
}
|
||||||
@@ -194,7 +184,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_message_sent()
|
|||||||
_tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
|
_tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
|
||||||
|
|
||||||
/* Tell the policy engine that we succeeded */
|
/* Tell the policy engine that we succeeded */
|
||||||
PolicyEngine::notify( PDB_EVT_PE_TX_DONE);
|
PolicyEngine::notify(PDB_EVT_PE_TX_DONE);
|
||||||
|
|
||||||
return PRLTxWaitMessage;
|
return PRLTxWaitMessage;
|
||||||
}
|
}
|
||||||
@@ -210,10 +200,10 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_discard_messag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ProtocolTransmit::thread(const void *args) {
|
void ProtocolTransmit::thread(const void *args) {
|
||||||
(void) args;
|
(void)args;
|
||||||
ProtocolTransmit::protocol_tx_state state = PRLTxPHYReset;
|
ProtocolTransmit::protocol_tx_state state = PRLTxPHYReset;
|
||||||
|
|
||||||
//Init the incoming message queue
|
// Init the incoming message queue
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
@@ -253,16 +243,14 @@ void ProtocolTransmit::thread(const void *args) {
|
|||||||
|
|
||||||
void ProtocolTransmit::notify(ProtocolTransmit::Notifications notification) {
|
void ProtocolTransmit::notify(ProtocolTransmit::Notifications notification) {
|
||||||
if (xEventGroupHandle != NULL) {
|
if (xEventGroupHandle != NULL) {
|
||||||
xEventGroupSetBits(xEventGroupHandle, (uint32_t) notification);
|
xEventGroupSetBits(xEventGroupHandle, (uint32_t)notification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolTransmit::init() {
|
void ProtocolTransmit::init() {
|
||||||
messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE,
|
messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE, sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
|
||||||
sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
|
|
||||||
|
|
||||||
osThreadStaticDef(pd_txTask, thread, PDB_PRIO_PRL, 0, TaskStackSize,
|
osThreadStaticDef(pd_txTask, thread, PDB_PRIO_PRL, 0, TaskStackSize, TaskBuffer, &TaskControlBlock);
|
||||||
TaskBuffer, &TaskControlBlock);
|
|
||||||
TaskHandle = osThreadCreate(osThread(pd_txTask), NULL);
|
TaskHandle = osThreadCreate(osThread(pd_txTask), NULL);
|
||||||
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
||||||
}
|
}
|
||||||
@@ -281,18 +269,15 @@ bool ProtocolTransmit::messagePending() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolTransmit::getMessage() {
|
void ProtocolTransmit::getMessage() {
|
||||||
//Loads the pending message into the buffer
|
// Loads the pending message into the buffer
|
||||||
if (messagesWaiting) {
|
if (messagesWaiting) {
|
||||||
xQueueReceive(messagesWaiting, &temp_msg, 1);
|
xQueueReceive(messagesWaiting, &temp_msg, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtocolTransmit::Notifications ProtocolTransmit::waitForEvent(uint32_t mask,
|
ProtocolTransmit::Notifications ProtocolTransmit::waitForEvent(uint32_t mask, TickType_t ticksToWait) {
|
||||||
TickType_t ticksToWait) {
|
|
||||||
if (xEventGroupHandle) {
|
if (xEventGroupHandle) {
|
||||||
return (Notifications) xEventGroupWaitBits(xEventGroupHandle, mask,
|
return (Notifications)xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE, ticksToWait);
|
||||||
mask,
|
|
||||||
pdFALSE, ticksToWait);
|
|
||||||
}
|
}
|
||||||
return (Notifications)0;
|
return (Notifications)0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,14 +6,14 @@
|
|||||||
*/
|
*/
|
||||||
#include "Model_Config.h"
|
#include "Model_Config.h"
|
||||||
#ifdef I2C_SOFT
|
#ifdef I2C_SOFT
|
||||||
#include <I2CBB.hpp>
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
|
#include <I2CBB.hpp>
|
||||||
SemaphoreHandle_t I2CBB::I2CSemaphore = NULL;
|
SemaphoreHandle_t I2CBB::I2CSemaphore = NULL;
|
||||||
StaticSemaphore_t I2CBB::xSemaphoreBuffer;
|
StaticSemaphore_t I2CBB::xSemaphoreBuffer;
|
||||||
SemaphoreHandle_t I2CBB::I2CSemaphore2 = NULL;
|
SemaphoreHandle_t I2CBB::I2CSemaphore2 = NULL;
|
||||||
StaticSemaphore_t I2CBB::xSemaphoreBuffer2;
|
StaticSemaphore_t I2CBB::xSemaphoreBuffer2;
|
||||||
void I2CBB::init() {
|
void I2CBB::init() {
|
||||||
//Set GPIO's to output open drain
|
// Set GPIO's to output open drain
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||||
@@ -32,7 +32,6 @@ void I2CBB::init() {
|
|||||||
I2CSemaphore2 = xSemaphoreCreateMutexStatic(&xSemaphoreBuffer2);
|
I2CSemaphore2 = xSemaphoreCreateMutexStatic(&xSemaphoreBuffer2);
|
||||||
unlock();
|
unlock();
|
||||||
unlock2();
|
unlock2();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool I2CBB::probe(uint8_t address) {
|
bool I2CBB::probe(uint8_t address) {
|
||||||
@@ -45,8 +44,7 @@ bool I2CBB::probe(uint8_t address) {
|
|||||||
return ack;
|
return ack;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool I2CBB::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData,
|
bool I2CBB::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, uint16_t Size) {
|
||||||
uint16_t Size) {
|
|
||||||
if (!lock())
|
if (!lock())
|
||||||
return false;
|
return false;
|
||||||
start();
|
start();
|
||||||
@@ -64,7 +62,7 @@ bool I2CBB::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData,
|
|||||||
}
|
}
|
||||||
SOFT_SCL_LOW();
|
SOFT_SCL_LOW();
|
||||||
SOFT_I2C_DELAY();
|
SOFT_I2C_DELAY();
|
||||||
// stop();
|
// stop();
|
||||||
start();
|
start();
|
||||||
ack = send(DevAddress | 1);
|
ack = send(DevAddress | 1);
|
||||||
if (!ack) {
|
if (!ack) {
|
||||||
@@ -82,8 +80,7 @@ bool I2CBB::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool I2CBB::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
bool I2CBB::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, const uint8_t *pData, uint16_t Size) {
|
||||||
const uint8_t *pData, uint16_t Size) {
|
|
||||||
if (!lock())
|
if (!lock())
|
||||||
return false;
|
return false;
|
||||||
start();
|
start();
|
||||||
@@ -140,7 +137,6 @@ void I2CBB::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
|||||||
}
|
}
|
||||||
stop();
|
stop();
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2CBB::Receive(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
void I2CBB::Receive(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
||||||
@@ -162,8 +158,7 @@ void I2CBB::Receive(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
|||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2CBB::TransmitReceive(uint16_t DevAddress, uint8_t *pData_tx,
|
void I2CBB::TransmitReceive(uint16_t DevAddress, uint8_t *pData_tx, uint16_t Size_tx, uint8_t *pData_rx, uint16_t Size_rx) {
|
||||||
uint16_t Size_tx, uint8_t *pData_rx, uint16_t Size_rx) {
|
|
||||||
if (Size_tx == 0 && Size_rx == 0)
|
if (Size_tx == 0 && Size_rx == 0)
|
||||||
return;
|
return;
|
||||||
if (lock() == false)
|
if (lock() == false)
|
||||||
@@ -273,15 +268,13 @@ uint8_t I2CBB::read_bit() {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2CBB::unlock() {
|
void I2CBB::unlock() { xSemaphoreGive(I2CSemaphore); }
|
||||||
xSemaphoreGive(I2CSemaphore);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool I2CBB::lock() {
|
bool I2CBB::lock() {
|
||||||
if (I2CSemaphore == NULL) {
|
if (I2CSemaphore == NULL) {
|
||||||
asm("bkpt");
|
asm("bkpt");
|
||||||
}
|
}
|
||||||
bool a = xSemaphoreTake(I2CSemaphore, (TickType_t) 100) == pdTRUE;
|
bool a = xSemaphoreTake(I2CSemaphore, (TickType_t)100) == pdTRUE;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,15 +291,13 @@ void I2CBB::write_bit(uint8_t val) {
|
|||||||
SOFT_SCL_LOW();
|
SOFT_SCL_LOW();
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2CBB::unlock2() {
|
void I2CBB::unlock2() { xSemaphoreGive(I2CSemaphore2); }
|
||||||
xSemaphoreGive(I2CSemaphore2);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool I2CBB::lock2() {
|
bool I2CBB::lock2() {
|
||||||
if (I2CSemaphore2 == NULL) {
|
if (I2CSemaphore2 == NULL) {
|
||||||
asm("bkpt");
|
asm("bkpt");
|
||||||
}
|
}
|
||||||
bool a = xSemaphoreTake(I2CSemaphore2, (TickType_t) 500) == pdTRUE;
|
bool a = xSemaphoreTake(I2CSemaphore2, (TickType_t)500) == pdTRUE;
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,34 +10,30 @@
|
|||||||
#include "LIS2DH12.hpp"
|
#include "LIS2DH12.hpp"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
static const FRToSI2C::I2C_REG i2c_registers[] = { { LIS_CTRL_REG1, 0x17, 0 }, // 25Hz
|
static const FRToSI2C::I2C_REG i2c_registers[] = {{LIS_CTRL_REG1, 0x17, 0}, // 25Hz
|
||||||
{ LIS_CTRL_REG2, 0b00001000, 0 }, // Highpass filter off
|
{LIS_CTRL_REG2, 0b00001000, 0}, // Highpass filter off
|
||||||
{ LIS_CTRL_REG3, 0b01100000, 0 }, // Setup interrupt pins
|
{LIS_CTRL_REG3, 0b01100000, 0}, // Setup interrupt pins
|
||||||
{ LIS_CTRL_REG4, 0b00001000, 0 }, // Block update mode off, HR on
|
{LIS_CTRL_REG4, 0b00001000, 0}, // Block update mode off, HR on
|
||||||
{ LIS_CTRL_REG5, 0b00000010, 0 }, //
|
{LIS_CTRL_REG5, 0b00000010, 0}, //
|
||||||
{ LIS_CTRL_REG6, 0b01100010, 0 },
|
{LIS_CTRL_REG6, 0b01100010, 0},
|
||||||
//Basically setup the unit to run, and enable 4D orientation detection
|
// Basically setup the unit to run, and enable 4D orientation detection
|
||||||
{ LIS_INT2_CFG, 0b01111110, 0 }, //setup for movement detection
|
{LIS_INT2_CFG, 0b01111110, 0}, // setup for movement detection
|
||||||
{ LIS_INT2_THS, 0x28, 0 }, //
|
{LIS_INT2_THS, 0x28, 0}, //
|
||||||
{ LIS_INT2_DURATION, 64, 0 }, //
|
{LIS_INT2_DURATION, 64, 0}, //
|
||||||
{ LIS_INT1_CFG, 0b01111110, 0 }, //
|
{LIS_INT1_CFG, 0b01111110, 0}, //
|
||||||
{ LIS_INT1_THS, 0x28, 0 }, //
|
{LIS_INT1_THS, 0x28, 0}, //
|
||||||
{ LIS_INT1_DURATION, 64, 0 } };
|
{LIS_INT1_DURATION, 64, 0}};
|
||||||
|
|
||||||
bool LIS2DH12::initalize() {
|
bool LIS2DH12::initalize() { return FRToSI2C::writeRegistersBulk(LIS2DH_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0])); }
|
||||||
return FRToSI2C::writeRegistersBulk(LIS2DH_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
void LIS2DH12::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
void LIS2DH12::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||||
std::array<int16_t, 3> sensorData;
|
std::array<int16_t, 3> sensorData;
|
||||||
|
|
||||||
FRToSI2C::Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8, reinterpret_cast<uint8_t*>(sensorData.begin()), sensorData.size() * sizeof(int16_t));
|
FRToSI2C::Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8, reinterpret_cast<uint8_t *>(sensorData.begin()), sensorData.size() * sizeof(int16_t));
|
||||||
|
|
||||||
x = sensorData[0];
|
x = sensorData[0];
|
||||||
y = sensorData[1];
|
y = sensorData[1];
|
||||||
z = sensorData[2];
|
z = sensorData[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LIS2DH12::detect() {
|
bool LIS2DH12::detect() { return FRToSI2C::probe(LIS2DH_I2C_ADDRESS); }
|
||||||
return FRToSI2C::probe(LIS2DH_I2C_ADDRESS);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -10,37 +10,33 @@
|
|||||||
#include "MMA8652FC.hpp"
|
#include "MMA8652FC.hpp"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
|
static const FRToSI2C::I2C_REG i2c_registers[] = {
|
||||||
static const FRToSI2C::I2C_REG i2c_registers[] = { { CTRL_REG2, 0, 0 }, //Normal mode
|
{CTRL_REG2, 0, 0}, // Normal mode
|
||||||
{ CTRL_REG2, 0x40, 2 }, // Reset all registers to POR values
|
{CTRL_REG2, 0x40, 2}, // Reset all registers to POR values
|
||||||
{ FF_MT_CFG_REG, 0x78, 0 }, // Enable motion detection for X, Y, Z axis, latch disabled
|
{FF_MT_CFG_REG, 0x78, 0}, // Enable motion detection for X, Y, Z axis, latch disabled
|
||||||
{ PL_CFG_REG, 0x40, 0 }, //Enable the orientation detection
|
{PL_CFG_REG, 0x40, 0}, // Enable the orientation detection
|
||||||
{ PL_COUNT_REG, 200, 0 }, //200 count debounce
|
{PL_COUNT_REG, 200, 0}, // 200 count debounce
|
||||||
{ PL_BF_ZCOMP_REG, 0b01000111, 0 }, //Set the threshold to 42 degrees
|
{PL_BF_ZCOMP_REG, 0b01000111, 0}, // Set the threshold to 42 degrees
|
||||||
{ P_L_THS_REG, 0b10011100, 0 }, //Up the trip angles
|
{P_L_THS_REG, 0b10011100, 0}, // Up the trip angles
|
||||||
{ CTRL_REG4, 0x01 | (1 << 4), 0 }, // Enable dataready interrupt & orientation interrupt
|
{CTRL_REG4, 0x01 | (1 << 4), 0}, // Enable dataready interrupt & orientation interrupt
|
||||||
{ CTRL_REG5, 0x01, 0 }, // Route data ready interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2
|
{CTRL_REG5, 0x01, 0}, // Route data ready interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2
|
||||||
{ CTRL_REG2, 0x12, 0 }, //Set maximum resolution oversampling
|
{CTRL_REG2, 0x12, 0}, // Set maximum resolution oversampling
|
||||||
{ XYZ_DATA_CFG_REG, (1 << 4), 0 }, //select high pass filtered data
|
{XYZ_DATA_CFG_REG, (1 << 4), 0}, // select high pass filtered data
|
||||||
{ HP_FILTER_CUTOFF_REG, 0x03, 0 }, //select high pass filtered data
|
{HP_FILTER_CUTOFF_REG, 0x03, 0}, // select high pass filtered data
|
||||||
{ CTRL_REG1, 0x19, 0 } // ODR=12 Hz, Active mode
|
{CTRL_REG1, 0x19, 0} // ODR=12 Hz, Active mode
|
||||||
};
|
};
|
||||||
|
|
||||||
bool MMA8652FC::initalize() {
|
bool MMA8652FC::initalize() { return FRToSI2C::writeRegistersBulk(MMA8652FC_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0])); }
|
||||||
return FRToSI2C::writeRegistersBulk(MMA8652FC_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Orientation MMA8652FC::getOrientation() {
|
Orientation MMA8652FC::getOrientation() {
|
||||||
//First read the PL_STATUS register
|
// First read the PL_STATUS register
|
||||||
uint8_t plStatus = FRToSI2C::I2C_RegisterRead(MMA8652FC_I2C_ADDRESS,
|
uint8_t plStatus = FRToSI2C::I2C_RegisterRead(MMA8652FC_I2C_ADDRESS, PL_STATUS_REG);
|
||||||
PL_STATUS_REG);
|
|
||||||
if ((plStatus & 0b10000000) == 0b10000000) {
|
if ((plStatus & 0b10000000) == 0b10000000) {
|
||||||
plStatus >>= 1; //We don't need the up/down bit
|
plStatus >>= 1; // We don't need the up/down bit
|
||||||
plStatus &= 0x03; //mask to the two lower bits
|
plStatus &= 0x03; // mask to the two lower bits
|
||||||
|
|
||||||
//0 == left handed
|
// 0 == left handed
|
||||||
//1 == right handed
|
// 1 == right handed
|
||||||
|
|
||||||
return static_cast<Orientation>(plStatus);
|
return static_cast<Orientation>(plStatus);
|
||||||
}
|
}
|
||||||
@@ -51,13 +47,11 @@ Orientation MMA8652FC::getOrientation() {
|
|||||||
void MMA8652FC::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
void MMA8652FC::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||||
std::array<int16_t, 3> sensorData;
|
std::array<int16_t, 3> sensorData;
|
||||||
|
|
||||||
FRToSI2C::Mem_Read(MMA8652FC_I2C_ADDRESS, OUT_X_MSB_REG, reinterpret_cast<uint8_t*>(sensorData.begin()), sensorData.size() * sizeof(int16_t));
|
FRToSI2C::Mem_Read(MMA8652FC_I2C_ADDRESS, OUT_X_MSB_REG, reinterpret_cast<uint8_t *>(sensorData.begin()), sensorData.size() * sizeof(int16_t));
|
||||||
|
|
||||||
x = static_cast<int16_t>(__builtin_bswap16(*reinterpret_cast<uint16_t*>(&sensorData[0])));
|
x = static_cast<int16_t>(__builtin_bswap16(*reinterpret_cast<uint16_t *>(&sensorData[0])));
|
||||||
y = static_cast<int16_t>(__builtin_bswap16(*reinterpret_cast<uint16_t*>(&sensorData[1])));
|
y = static_cast<int16_t>(__builtin_bswap16(*reinterpret_cast<uint16_t *>(&sensorData[1])));
|
||||||
z = static_cast<int16_t>(__builtin_bswap16(*reinterpret_cast<uint16_t*>(&sensorData[2])));
|
z = static_cast<int16_t>(__builtin_bswap16(*reinterpret_cast<uint16_t *>(&sensorData[2])));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MMA8652FC::detect() {
|
bool MMA8652FC::detect() { return FRToSI2C::probe(MMA8652FC_I2C_ADDRESS); }
|
||||||
return FRToSI2C::probe(MMA8652FC_I2C_ADDRESS);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,26 +5,23 @@
|
|||||||
* Author: Ralim
|
* Author: Ralim
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <MSA301.h>
|
|
||||||
#include "MSA301_defines.h"
|
#include "MSA301_defines.h"
|
||||||
|
#include <MSA301.h>
|
||||||
#define MSA301_I2C_ADDRESS 0x4C
|
#define MSA301_I2C_ADDRESS 0x4C
|
||||||
bool MSA301::detect() {
|
bool MSA301::detect() { return FRToSI2C::probe(MSA301_I2C_ADDRESS); }
|
||||||
return FRToSI2C::probe(MSA301_I2C_ADDRESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const FRToSI2C::I2C_REG i2c_registers[] = { //
|
static const FRToSI2C::I2C_REG i2c_registers[] = {
|
||||||
//
|
//
|
||||||
{ MSA301_REG_ODR, 0b00001000, 1 }, //X/Y/Z enabled @ 250Hz
|
//
|
||||||
{ MSA301_REG_POWERMODE, 0b0001001, 1 }, // Normal mode
|
{MSA301_REG_ODR, 0b00001000, 1}, // X/Y/Z enabled @ 250Hz
|
||||||
{ MSA301_REG_RESRANGE, 0b00000001, 0 }, // 14bit resolution @ 4G range
|
{MSA301_REG_POWERMODE, 0b0001001, 1}, // Normal mode
|
||||||
{ MSA301_REG_ORIENT_HY, 0b01000000, 0 }, // 4*62.5mg hyst, no blocking, symmetrical
|
{MSA301_REG_RESRANGE, 0b00000001, 0}, // 14bit resolution @ 4G range
|
||||||
{ MSA301_REG_INTSET0, 1 << 6, 0 }, // Turn on orientation detection (by enabling its interrupt)
|
{MSA301_REG_ORIENT_HY, 0b01000000, 0}, // 4*62.5mg hyst, no blocking, symmetrical
|
||||||
|
{MSA301_REG_INTSET0, 1 << 6, 0}, // Turn on orientation detection (by enabling its interrupt)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool MSA301::initalize() {
|
bool MSA301::initalize() { return FRToSI2C::writeRegistersBulk(MSA301_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0])); }
|
||||||
return FRToSI2C::writeRegistersBulk(MSA301_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
Orientation MSA301::getOrientation() {
|
Orientation MSA301::getOrientation() {
|
||||||
uint8_t temp = 0;
|
uint8_t temp = 0;
|
||||||
@@ -41,10 +38,9 @@ Orientation MSA301::getOrientation() {
|
|||||||
|
|
||||||
void MSA301::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
void MSA301::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||||
uint8_t temp[6];
|
uint8_t temp[6];
|
||||||
//Bulk read all 6 regs
|
// Bulk read all 6 regs
|
||||||
FRToSI2C::Mem_Read(MSA301_I2C_ADDRESS, MSA301_REG_OUT_X_L, temp, 6);
|
FRToSI2C::Mem_Read(MSA301_I2C_ADDRESS, MSA301_REG_OUT_X_L, temp, 6);
|
||||||
x = int16_t(((int16_t) temp[1]) << 8 | temp[0]) >> 2;
|
x = int16_t(((int16_t)temp[1]) << 8 | temp[0]) >> 2;
|
||||||
y = int16_t(((int16_t) temp[3]) << 8 | temp[2]) >> 2;
|
y = int16_t(((int16_t)temp[3]) << 8 | temp[2]) >> 2;
|
||||||
z = int16_t(((int16_t) temp[5]) << 8 | temp[4]) >> 2;
|
z = int16_t(((int16_t)temp[5]) << 8 | temp[4]) >> 2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
* Author: Ben V. Brown
|
* Author: Ben V. Brown
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include "../../configuration.h"
|
||||||
#include <OLED.hpp>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "Translation.h"
|
#include "Translation.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "../../configuration.h"
|
#include <OLED.hpp>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
const uint8_t *OLED::currentFont; // Pointer to the current font used for
|
const uint8_t *OLED::currentFont; // Pointer to the current font used for
|
||||||
// rendering to the buffer
|
// rendering to the buffer
|
||||||
@@ -32,36 +32,36 @@ uint8_t OLED::secondFrameBuffer[OLED_WIDTH * 2];
|
|||||||
/*All commands are prefixed with 0x80*/
|
/*All commands are prefixed with 0x80*/
|
||||||
/*Data packets are prefixed with 0x40*/
|
/*Data packets are prefixed with 0x40*/
|
||||||
FRToSI2C::I2C_REG OLED_Setup_Array[] = {
|
FRToSI2C::I2C_REG OLED_Setup_Array[] = {
|
||||||
/**/
|
/**/
|
||||||
{ 0x80, 0xAE, 0 }, /*Display off*/
|
{0x80, 0xAE, 0}, /*Display off*/
|
||||||
{ 0x80, 0xD5, 0 }, /*Set display clock divide ratio / osc freq*/
|
{0x80, 0xD5, 0}, /*Set display clock divide ratio / osc freq*/
|
||||||
{ 0x80, 0x52, 0 }, /*Divide ratios*/
|
{0x80, 0x52, 0}, /*Divide ratios*/
|
||||||
{ 0x80, 0xA8, 0 }, /*Set Multiplex Ratio*/
|
{0x80, 0xA8, 0}, /*Set Multiplex Ratio*/
|
||||||
{ 0x80, 0x0F, 0 }, /*16 == max brightness,39==dimmest*/
|
{0x80, 0x0F, 0}, /*16 == max brightness,39==dimmest*/
|
||||||
{ 0x80, 0xC0, 0 }, /*Set COM Scan direction*/
|
{0x80, 0xC0, 0}, /*Set COM Scan direction*/
|
||||||
{ 0x80, 0xD3, 0 }, /*Set vertical Display offset*/
|
{0x80, 0xD3, 0}, /*Set vertical Display offset*/
|
||||||
{ 0x80, 0x00, 0 }, /*0 Offset*/
|
{0x80, 0x00, 0}, /*0 Offset*/
|
||||||
{ 0x80, 0x40, 0 }, /*Set Display start line to 0*/
|
{0x80, 0x40, 0}, /*Set Display start line to 0*/
|
||||||
{ 0x80, 0xA0, 0 }, /*Set Segment remap to normal*/
|
{0x80, 0xA0, 0}, /*Set Segment remap to normal*/
|
||||||
{ 0x80, 0x8D, 0 }, /*Charge Pump*/
|
{0x80, 0x8D, 0}, /*Charge Pump*/
|
||||||
{ 0x80, 0x14, 0 }, /*Charge Pump settings*/
|
{0x80, 0x14, 0}, /*Charge Pump settings*/
|
||||||
{ 0x80, 0xDA, 0 }, /*Set VCOM Pins hardware config*/
|
{0x80, 0xDA, 0}, /*Set VCOM Pins hardware config*/
|
||||||
{ 0x80, 0x02, 0 }, /*Combination 2*/
|
{0x80, 0x02, 0}, /*Combination 2*/
|
||||||
{ 0x80, 0x81, 0 }, /*Contrast*/
|
{0x80, 0x81, 0}, /*Contrast*/
|
||||||
{ 0x80, 0x33, 0 }, /*^51*/
|
{0x80, 0x33, 0}, /*^51*/
|
||||||
{ 0x80, 0xD9, 0 }, /*Set pre-charge period*/
|
{0x80, 0xD9, 0}, /*Set pre-charge period*/
|
||||||
{ 0x80, 0xF1, 0 }, /*Pre charge period*/
|
{0x80, 0xF1, 0}, /*Pre charge period*/
|
||||||
{ 0x80, 0xDB, 0 }, /*Adjust VCOMH regulator ouput*/
|
{0x80, 0xDB, 0}, /*Adjust VCOMH regulator ouput*/
|
||||||
{ 0x80, 0x30, 0 }, /*VCOM level*/
|
{0x80, 0x30, 0}, /*VCOM level*/
|
||||||
{ 0x80, 0xA4, 0 }, /*Enable the display GDDR*/
|
{0x80, 0xA4, 0}, /*Enable the display GDDR*/
|
||||||
{ 0x80, 0XA6, 0 }, /*Normal display*/
|
{0x80, 0XA6, 0}, /*Normal display*/
|
||||||
{ 0x80, 0x20, 0 }, /*Memory Mode*/
|
{0x80, 0x20, 0}, /*Memory Mode*/
|
||||||
{ 0x80, 0x00, 0 }, /*Wrap memory*/
|
{0x80, 0x00, 0}, /*Wrap memory*/
|
||||||
{ 0x80, 0xAF, 0 }, /*Display on*/
|
{0x80, 0xAF, 0}, /*Display on*/
|
||||||
};
|
};
|
||||||
// Setup based on the SSD1307 and modified for the SSD1306
|
// Setup based on the SSD1307 and modified for the SSD1306
|
||||||
|
|
||||||
const uint8_t REFRESH_COMMANDS[17] = { 0x80, 0xAF, 0x80, 0x21, 0x80, 0x20, 0x80, 0x7F, 0x80, 0xC0, 0x80, 0x22, 0x80, 0x00, 0x80, 0x01, 0x40 };
|
const uint8_t REFRESH_COMMANDS[17] = {0x80, 0xAF, 0x80, 0x21, 0x80, 0x20, 0x80, 0x7F, 0x80, 0xC0, 0x80, 0x22, 0x80, 0x00, 0x80, 0x01, 0x40};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Animation timing function that follows a bezier curve.
|
* Animation timing function that follows a bezier curve.
|
||||||
@@ -69,9 +69,7 @@ const uint8_t REFRESH_COMMANDS[17] = { 0x80, 0xAF, 0x80, 0x21, 0x80, 0x20, 0x80,
|
|||||||
* Returns a new percentage value with ease in and ease out.
|
* Returns a new percentage value with ease in and ease out.
|
||||||
* Original floating point formula: t * t * (3.0f - 2.0f * t);
|
* Original floating point formula: t * t * (3.0f - 2.0f * t);
|
||||||
*/
|
*/
|
||||||
static uint8_t easeInOutTiming(uint8_t t) {
|
static uint8_t easeInOutTiming(uint8_t t) { return t * t * (300 - 2 * t) / 10000; }
|
||||||
return t * t * (300 - 2 * t) / 10000;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the value between a and b, using a percentage value t.
|
* Returns the value between a and b, using a percentage value t.
|
||||||
@@ -79,9 +77,7 @@ static uint8_t easeInOutTiming(uint8_t t) {
|
|||||||
* @param b The value associated with 100%
|
* @param b The value associated with 100%
|
||||||
* @param t The percentage [0..<100]
|
* @param t The percentage [0..<100]
|
||||||
*/
|
*/
|
||||||
static uint8_t lerp(uint8_t a, uint8_t b, uint8_t t) {
|
static uint8_t lerp(uint8_t a, uint8_t b, uint8_t t) { return a + t * (b - a) / 100; }
|
||||||
return a + t * (b - a) / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OLED::initialize() {
|
void OLED::initialize() {
|
||||||
cursor_x = cursor_y = 0;
|
cursor_x = cursor_y = 0;
|
||||||
@@ -129,9 +125,9 @@ void OLED::drawChar(char c) {
|
|||||||
} else if (c == 0) {
|
} else if (c == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint16_t index = c - 2; //First index is \x02
|
uint16_t index = c - 2; // First index is \x02
|
||||||
uint8_t *charPointer;
|
uint8_t *charPointer;
|
||||||
charPointer = ((uint8_t*) currentFont) + ((fontWidth * (fontHeight / 8)) * index);
|
charPointer = ((uint8_t *)currentFont) + ((fontWidth * (fontHeight / 8)) * index);
|
||||||
drawArea(cursor_x, cursor_y, fontWidth, fontHeight, charPointer);
|
drawArea(cursor_x, cursor_y, fontWidth, fontHeight, charPointer);
|
||||||
cursor_x += fontWidth;
|
cursor_x += fontWidth;
|
||||||
}
|
}
|
||||||
@@ -180,22 +176,20 @@ void OLED::transitionSecondaryFramebuffer(bool forwardNavigation) {
|
|||||||
progress = OLED_WIDTH;
|
progress = OLED_WIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When forward, current contents move to the left out.
|
// When forward, current contents move to the left out.
|
||||||
// Otherwise the contents move to the right out.
|
// Otherwise the contents move to the right out.
|
||||||
uint8_t oldStart = forwardNavigation ? 0 : progress;
|
uint8_t oldStart = forwardNavigation ? 0 : progress;
|
||||||
uint8_t oldPrevious = forwardNavigation ? progress - offset : offset;
|
uint8_t oldPrevious = forwardNavigation ? progress - offset : offset;
|
||||||
|
|
||||||
// Content from the second framebuffer moves in from the right (forward)
|
// Content from the second framebuffer moves in from the right (forward)
|
||||||
// or from the left (not forward).
|
// or from the left (not forward).
|
||||||
uint8_t newStart = forwardNavigation ? OLED_WIDTH - progress : 0;
|
uint8_t newStart = forwardNavigation ? OLED_WIDTH - progress : 0;
|
||||||
uint8_t newEnd = forwardNavigation ? 0 : OLED_WIDTH - progress;
|
uint8_t newEnd = forwardNavigation ? 0 : OLED_WIDTH - progress;
|
||||||
|
|
||||||
offset = progress;
|
offset = progress;
|
||||||
|
|
||||||
memmove(&firstStripPtr[oldStart], &firstStripPtr[oldPrevious],
|
memmove(&firstStripPtr[oldStart], &firstStripPtr[oldPrevious], OLED_WIDTH - progress);
|
||||||
OLED_WIDTH - progress);
|
memmove(&secondStripPtr[oldStart], &secondStripPtr[oldPrevious], OLED_WIDTH - progress);
|
||||||
memmove(&secondStripPtr[oldStart], &secondStripPtr[oldPrevious],
|
|
||||||
OLED_WIDTH - progress);
|
|
||||||
|
|
||||||
memmove(&firstStripPtr[newStart], &firstBackStripPtr[newEnd], progress);
|
memmove(&firstStripPtr[newStart], &firstBackStripPtr[newEnd], progress);
|
||||||
memmove(&secondStripPtr[newStart], &secondBackStripPtr[newEnd], progress);
|
memmove(&secondStripPtr[newStart], &secondBackStripPtr[newEnd], progress);
|
||||||
@@ -249,7 +243,7 @@ void OLED::print(const char *str) {
|
|||||||
|
|
||||||
void OLED::setFont(uint8_t fontNumber) {
|
void OLED::setFont(uint8_t fontNumber) {
|
||||||
if (fontNumber == 1) {
|
if (fontNumber == 1) {
|
||||||
// small font
|
// small font
|
||||||
currentFont = USER_FONT_6x8;
|
currentFont = USER_FONT_6x8;
|
||||||
fontHeight = 8;
|
fontHeight = 8;
|
||||||
fontWidth = 6;
|
fontWidth = 6;
|
||||||
@@ -272,7 +266,7 @@ uint8_t OLED::getFont() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
inline void stripLeaderZeros(char *buffer, uint8_t places) {
|
inline void stripLeaderZeros(char *buffer, uint8_t places) {
|
||||||
//Removing the leading zero's by swapping them to SymbolSpace
|
// Removing the leading zero's by swapping them to SymbolSpace
|
||||||
// Stop 1 short so that we dont blank entire number if its zero
|
// Stop 1 short so that we dont blank entire number if its zero
|
||||||
for (int i = 0; i < (places - 1); i++) {
|
for (int i = 0; i < (places - 1); i++) {
|
||||||
if (buffer[i] == 2) {
|
if (buffer[i] == 2) {
|
||||||
@@ -284,7 +278,7 @@ inline void stripLeaderZeros(char *buffer, uint8_t places) {
|
|||||||
}
|
}
|
||||||
// maximum places is 5
|
// maximum places is 5
|
||||||
void OLED::printNumber(uint16_t number, uint8_t places, bool noLeaderZeros) {
|
void OLED::printNumber(uint16_t number, uint8_t places, bool noLeaderZeros) {
|
||||||
char buffer[7] = { 0 };
|
char buffer[7] = {0};
|
||||||
|
|
||||||
if (places >= 5) {
|
if (places >= 5) {
|
||||||
buffer[5] = 2 + number % 10;
|
buffer[5] = 2 + number % 10;
|
||||||
@@ -357,13 +351,13 @@ void OLED::drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (y == 0) {
|
if (y == 0) {
|
||||||
// Splat first line of data
|
// Splat first line of data
|
||||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||||
firstStripPtr[xx + x] = ptr[xx];
|
firstStripPtr[xx + x] = ptr[xx];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (y == 8 || height == 16) {
|
if (y == 8 || height == 16) {
|
||||||
// Splat the second line
|
// Splat the second line
|
||||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||||
secondStripPtr[x + xx] = ptr[xx + (height == 16 ? wide : 0)];
|
secondStripPtr[x + xx] = ptr[xx + (height == 16 ? wide : 0)];
|
||||||
}
|
}
|
||||||
@@ -425,13 +419,13 @@ void OLED::fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (y == 0) {
|
if (y == 0) {
|
||||||
// Splat first line of data
|
// Splat first line of data
|
||||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||||
firstStripPtr[xx + x] = value;
|
firstStripPtr[xx + x] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (y == 8 || height == 16) {
|
if (y == 8 || height == 16) {
|
||||||
// Splat the second line
|
// Splat the second line
|
||||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||||
secondStripPtr[x + xx] = value;
|
secondStripPtr[x + xx] = value;
|
||||||
}
|
}
|
||||||
@@ -484,6 +478,4 @@ void OLED::drawHeatSymbol(uint8_t state) {
|
|||||||
drawFilledRect(cursor_x_temp, 0, cursor_x_temp + 12, 2 + (8 - state), true);
|
drawFilledRect(cursor_x_temp, 0, cursor_x_temp + 12, 2 + (8 - state), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OLED::isInitDone() {
|
bool OLED::isInitDone() { return initDone; }
|
||||||
return initDone;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
bool SC7A20::detect() {
|
bool SC7A20::detect() {
|
||||||
if (FRToSI2C::probe(SC7A20_ADDRESS)) {
|
if (FRToSI2C::probe(SC7A20_ADDRESS)) {
|
||||||
//Read chip id to ensure its not an address collision
|
// Read chip id to ensure its not an address collision
|
||||||
uint8_t id = 0;
|
uint8_t id = 0;
|
||||||
if (FRToSI2C::Mem_Read(SC7A20_ADDRESS, SC7A20_WHO_AMI_I, &id, 1)) {
|
if (FRToSI2C::Mem_Read(SC7A20_ADDRESS, SC7A20_WHO_AMI_I, &id, 1)) {
|
||||||
return id == 0b00010001;
|
return id == 0b00010001;
|
||||||
@@ -21,49 +21,48 @@ bool SC7A20::detect() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const FRToSI2C::I2C_REG i2c_registers[] = { //
|
static const FRToSI2C::I2C_REG i2c_registers[] = {
|
||||||
//
|
//
|
||||||
{ SC7A20_CTRL_REG1, 0b01100111, 0 }, //200Hz, XYZ enabled
|
//
|
||||||
{ SC7A20_CTRL_REG2, 0b00000000, 0 }, //Setup filter to 0x00 ??
|
{SC7A20_CTRL_REG1, 0b01100111, 0}, // 200Hz, XYZ enabled
|
||||||
{ SC7A20_CTRL_REG3, 0b00000000, 0 }, //int1 off
|
{SC7A20_CTRL_REG2, 0b00000000, 0}, // Setup filter to 0x00 ??
|
||||||
{ SC7A20_CTRL_REG4, 0b01001000, 0 }, //Block mode off,little-endian,2G,High-pres,self test off
|
{SC7A20_CTRL_REG3, 0b00000000, 0}, // int1 off
|
||||||
{ SC7A20_CTRL_REG5, 0b00000100, 0 }, //fifo off, D4D on int1
|
{SC7A20_CTRL_REG4, 0b01001000, 0}, // Block mode off,little-endian,2G,High-pres,self test off
|
||||||
{ SC7A20_CTRL_REG6, 0x00, 0 }, //INT2 off
|
{SC7A20_CTRL_REG5, 0b00000100, 0}, // fifo off, D4D on int1
|
||||||
//Basically setup the unit to run, and enable 4D orientation detection
|
{SC7A20_CTRL_REG6, 0x00, 0}, // INT2 off
|
||||||
{ SC7A20_INT2_CFG, 0b01111110, 0 }, //setup for movement detection
|
// Basically setup the unit to run, and enable 4D orientation detection
|
||||||
{ SC7A20_INT2_THS, 0x28, 0 }, //
|
{SC7A20_INT2_CFG, 0b01111110, 0}, // setup for movement detection
|
||||||
{ SC7A20_INT2_DURATION, 64, 0 }, //
|
{SC7A20_INT2_THS, 0x28, 0}, //
|
||||||
{ SC7A20_INT1_CFG, 0b01111110, 0 }, //
|
{SC7A20_INT2_DURATION, 64, 0}, //
|
||||||
{ SC7A20_INT1_THS, 0x28, 0 }, //
|
{SC7A20_INT1_CFG, 0b01111110, 0}, //
|
||||||
{ SC7A20_INT1_DURATION, 64, 0 }
|
{SC7A20_INT1_THS, 0x28, 0}, //
|
||||||
|
{SC7A20_INT1_DURATION, 64, 0}
|
||||||
|
|
||||||
//
|
//
|
||||||
};
|
};
|
||||||
bool SC7A20::initalize() {
|
bool SC7A20::initalize() {
|
||||||
//Setup acceleration readings
|
// Setup acceleration readings
|
||||||
//2G range
|
// 2G range
|
||||||
//bandwidth = 250Hz
|
// bandwidth = 250Hz
|
||||||
//High pass filter on (Slow compensation)
|
// High pass filter on (Slow compensation)
|
||||||
//Turn off IRQ output pins
|
// Turn off IRQ output pins
|
||||||
//Orientation recognition in symmetrical mode
|
// Orientation recognition in symmetrical mode
|
||||||
// Hysteresis is set to ~ 16 counts
|
// Hysteresis is set to ~ 16 counts
|
||||||
//Theta blocking is set to 0b10
|
// Theta blocking is set to 0b10
|
||||||
|
|
||||||
return FRToSI2C::writeRegistersBulk(SC7A20_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
return FRToSI2C::writeRegistersBulk(SC7A20_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SC7A20::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
void SC7A20::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||||
//We can tell the accelerometer to output in LE mode which makes this simple
|
// We can tell the accelerometer to output in LE mode which makes this simple
|
||||||
uint16_t sensorData[3] = { 0, 0, 0 };
|
uint16_t sensorData[3] = {0, 0, 0};
|
||||||
|
|
||||||
if (FRToSI2C::Mem_Read(SC7A20_ADDRESS, SC7A20_OUT_X_L, (uint8_t*) sensorData, 6) == false) {
|
if (FRToSI2C::Mem_Read(SC7A20_ADDRESS, SC7A20_OUT_X_L, (uint8_t *)sensorData, 6) == false) {
|
||||||
x = y = z = 0;
|
x = y = z = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Shift 6 to make its range ~= the other accelerometers
|
// Shift 6 to make its range ~= the other accelerometers
|
||||||
x = sensorData[0];
|
x = sensorData[0];
|
||||||
y = sensorData[1];
|
y = sensorData[1];
|
||||||
z = sensorData[2];
|
z = sensorData[2];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,17 +10,14 @@
|
|||||||
* This class is licensed as MIT to match this code base
|
* This class is licensed as MIT to match this code base
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Si7210.h>
|
|
||||||
#include "Si7210_defines.h"
|
|
||||||
#include "I2C_Wrapper.hpp"
|
#include "I2C_Wrapper.hpp"
|
||||||
bool Si7210::detect() {
|
#include "Si7210_defines.h"
|
||||||
return FRToSI2C::wakePart(SI7210_ADDRESS);
|
#include <Si7210.h>
|
||||||
|
bool Si7210::detect() { return FRToSI2C::wakePart(SI7210_ADDRESS); }
|
||||||
}
|
|
||||||
|
|
||||||
bool Si7210::init() {
|
bool Si7210::init() {
|
||||||
//Turn on auto increment and sanity check ID
|
// Turn on auto increment and sanity check ID
|
||||||
//Load OTP cal
|
// Load OTP cal
|
||||||
|
|
||||||
uint8_t temp;
|
uint8_t temp;
|
||||||
if (FRToSI2C::Mem_Read(SI7210_ADDRESS, SI7210_REG_ID, &temp, 1)) {
|
if (FRToSI2C::Mem_Read(SI7210_ADDRESS, SI7210_REG_ID, &temp, 1)) {
|
||||||
@@ -29,12 +26,12 @@ bool Si7210::init() {
|
|||||||
temp = 0x00;
|
temp = 0x00;
|
||||||
|
|
||||||
/* Set device and internal driver settings */
|
/* Set device and internal driver settings */
|
||||||
if (!write_reg( SI7210_CTRL1, (uint8_t) ~SW_LOW4FIELD_MASK, 0)) {
|
if (!write_reg(SI7210_CTRL1, (uint8_t)~SW_LOW4FIELD_MASK, 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable periodic auto-wakeup by device, and tamper detect. */
|
/* Disable periodic auto-wakeup by device, and tamper detect. */
|
||||||
if ((!write_reg(SI7210_CTRL3, (uint8_t) ~SL_TIMEENA_MASK, 0)))
|
if ((!write_reg(SI7210_CTRL3, (uint8_t)~SL_TIMEENA_MASK, 0)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Disable tamper detection by setting sw_tamper to 63 */
|
/* Disable tamper detection by setting sw_tamper to 63 */
|
||||||
@@ -45,7 +42,7 @@ bool Si7210::init() {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Stop the control loop by setting stop bit */
|
/* Stop the control loop by setting stop bit */
|
||||||
if (!write_reg( SI7210_POWER_CTRL, MEAS_MASK | USESTORE_MASK, STOP_MASK)) /* WARNING: Removed USE_STORE MASK */
|
if (!write_reg(SI7210_POWER_CTRL, MEAS_MASK | USESTORE_MASK, STOP_MASK)) /* WARNING: Removed USE_STORE MASK */
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Use a burst size of 128/4096 samples in FIR and IIR modes */
|
/* Use a burst size of 128/4096 samples in FIR and IIR modes */
|
||||||
@@ -53,18 +50,17 @@ bool Si7210::init() {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Select field strength measurement */
|
/* Select field strength measurement */
|
||||||
if (!write_reg( SI7210_DSPSIGSEL, 0, DSP_SIGSEL_FIELD_MASK))
|
if (!write_reg(SI7210_DSPSIGSEL, 0, DSP_SIGSEL_FIELD_MASK))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true; //start_periodic_measurement();
|
return true; // start_periodic_measurement();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t Si7210::read() {
|
int16_t Si7210::read() {
|
||||||
//Read the two regs
|
// Read the two regs
|
||||||
int16_t temp = 0;
|
int16_t temp = 0;
|
||||||
if (!get_field_strength(&temp)) {
|
if (!get_field_strength(&temp)) {
|
||||||
temp = 0;
|
temp = 0;
|
||||||
@@ -84,101 +80,98 @@ bool Si7210::write_reg(const uint8_t reg, const uint8_t mask, const uint8_t val)
|
|||||||
return FRToSI2C::Mem_Write(SI7210_ADDRESS, reg, &temp, 1);
|
return FRToSI2C::Mem_Write(SI7210_ADDRESS, reg, &temp, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Si7210::read_reg(const uint8_t reg, uint8_t* val) {
|
bool Si7210::read_reg(const uint8_t reg, uint8_t *val) { return FRToSI2C::Mem_Read(SI7210_ADDRESS, reg, val, 1); }
|
||||||
return FRToSI2C::Mem_Read(SI7210_ADDRESS, reg, val, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Si7210::start_periodic_measurement() {
|
bool Si7210::start_periodic_measurement() {
|
||||||
/* Enable periodic wakeup */
|
/* Enable periodic wakeup */
|
||||||
if (!write_reg(SI7210_CTRL3, (uint8_t) ~SL_TIMEENA_MASK, SL_TIMEENA_MASK))
|
if (!write_reg(SI7210_CTRL3, (uint8_t)~SL_TIMEENA_MASK, SL_TIMEENA_MASK))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Start measurement */
|
/* Start measurement */
|
||||||
/* Change to ~STOP_MASK with STOP_MASK */
|
/* Change to ~STOP_MASK with STOP_MASK */
|
||||||
return write_reg( SI7210_POWER_CTRL, MEAS_MASK | USESTORE_MASK, 0);
|
return write_reg(SI7210_POWER_CTRL, MEAS_MASK | USESTORE_MASK, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Si7210::get_field_strength(int16_t* field) {
|
bool Si7210::get_field_strength(int16_t *field) {
|
||||||
*field = 0;
|
*field = 0;
|
||||||
uint8_t val = 0;
|
uint8_t val = 0;
|
||||||
FRToSI2C::wakePart(SI7210_ADDRESS);
|
FRToSI2C::wakePart(SI7210_ADDRESS);
|
||||||
|
|
||||||
if (!write_reg( SI7210_POWER_CTRL, MEAS_MASK | USESTORE_MASK, STOP_MASK))
|
if (!write_reg(SI7210_POWER_CTRL, MEAS_MASK | USESTORE_MASK, STOP_MASK))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Read most-significant byte */
|
/* Read most-significant byte */
|
||||||
if (!read_reg( SI7210_DSPSIGM, &val))
|
if (!read_reg(SI7210_DSPSIGM, &val))
|
||||||
return false;
|
return false;
|
||||||
*field = (val & DSP_SIGM_DATA_MASK) << 8;
|
*field = (val & DSP_SIGM_DATA_MASK) << 8;
|
||||||
|
|
||||||
/* Read least-significant byte of data */
|
/* Read least-significant byte of data */
|
||||||
if (!read_reg( SI7210_DSPSIGL, &val))
|
if (!read_reg(SI7210_DSPSIGL, &val))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*field += val;
|
*field += val;
|
||||||
*field -= 16384U;
|
*field -= 16384U;
|
||||||
//field is now a +- measurement
|
// field is now a +- measurement
|
||||||
//In units of 0.0125 mT
|
// In units of 0.0125 mT
|
||||||
// Aka 12.5uT
|
// Aka 12.5uT
|
||||||
//Clear flags
|
// Clear flags
|
||||||
read_reg( SI7210_CTRL1, &val);
|
read_reg(SI7210_CTRL1, &val);
|
||||||
read_reg( SI7210_CTRL2, &val);
|
read_reg(SI7210_CTRL2, &val);
|
||||||
//Start next one
|
// Start next one
|
||||||
|
|
||||||
/* Use a burst size of 128/4096 samples in FIR and IIR modes */
|
/* Use a burst size of 128/4096 samples in FIR and IIR modes */
|
||||||
write_reg( SI7210_CTRL4, 0, DF_BURSTSIZE_128 | DF_BW_4096);
|
write_reg(SI7210_CTRL4, 0, DF_BURSTSIZE_128 | DF_BW_4096);
|
||||||
|
|
||||||
/* Selet field strength measurement */
|
/* Selet field strength measurement */
|
||||||
write_reg( SI7210_DSPSIGSEL, 0, DSP_SIGSEL_FIELD_MASK);
|
write_reg(SI7210_DSPSIGSEL, 0, DSP_SIGSEL_FIELD_MASK);
|
||||||
|
|
||||||
/* Start measurement */
|
/* Start measurement */
|
||||||
write_reg( SI7210_POWER_CTRL, MEAS_MASK | USESTORE_MASK, ONEBURST_MASK);
|
write_reg(SI7210_POWER_CTRL, MEAS_MASK | USESTORE_MASK, ONEBURST_MASK);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Si7210::set_high_range() {
|
bool Si7210::set_high_range() {
|
||||||
//To set the unit into 200mT range, no magnet temperature calibration
|
// To set the unit into 200mT range, no magnet temperature calibration
|
||||||
// We want to copy OTP 0x27->0x2C into a0->a5
|
// We want to copy OTP 0x27->0x2C into a0->a5
|
||||||
uint8_t base_addr = 0x27; // You can change this to pick the temp calibration
|
uint8_t base_addr = 0x27; // You can change this to pick the temp calibration
|
||||||
bool worked = true;
|
bool worked = true;
|
||||||
uint8_t val = 0;
|
uint8_t val = 0;
|
||||||
|
|
||||||
/* Load A0 register */
|
/* Load A0 register */
|
||||||
worked &= write_reg( SI7210_OTP_ADDR, 0, base_addr);
|
worked &= write_reg(SI7210_OTP_ADDR, 0, base_addr);
|
||||||
worked &= write_reg( SI7210_OTP_CTRL, 0, OTP_READ_EN_MASK);
|
worked &= write_reg(SI7210_OTP_CTRL, 0, OTP_READ_EN_MASK);
|
||||||
worked &= read_reg( SI7210_OTP_DATA, &val);
|
worked &= read_reg(SI7210_OTP_DATA, &val);
|
||||||
worked &= write_reg( SI7210_A0, 0, val);
|
worked &= write_reg(SI7210_A0, 0, val);
|
||||||
|
|
||||||
/* Load A1 register */
|
/* Load A1 register */
|
||||||
worked &= write_reg( SI7210_OTP_ADDR, 0, base_addr + 1);
|
worked &= write_reg(SI7210_OTP_ADDR, 0, base_addr + 1);
|
||||||
worked &= write_reg( SI7210_OTP_CTRL, 0, OTP_READ_EN_MASK);
|
worked &= write_reg(SI7210_OTP_CTRL, 0, OTP_READ_EN_MASK);
|
||||||
worked &= read_reg( SI7210_OTP_DATA, &val);
|
worked &= read_reg(SI7210_OTP_DATA, &val);
|
||||||
worked &= write_reg( SI7210_A1, 0, val);
|
worked &= write_reg(SI7210_A1, 0, val);
|
||||||
|
|
||||||
/* Load A2 register */
|
/* Load A2 register */
|
||||||
worked &= write_reg( SI7210_OTP_ADDR, 0, base_addr + 2);
|
worked &= write_reg(SI7210_OTP_ADDR, 0, base_addr + 2);
|
||||||
worked &= write_reg( SI7210_OTP_CTRL, 0, OTP_READ_EN_MASK);
|
worked &= write_reg(SI7210_OTP_CTRL, 0, OTP_READ_EN_MASK);
|
||||||
worked &= read_reg( SI7210_OTP_DATA, &val);
|
worked &= read_reg(SI7210_OTP_DATA, &val);
|
||||||
worked &= write_reg( SI7210_A2, 0, val);
|
worked &= write_reg(SI7210_A2, 0, val);
|
||||||
|
|
||||||
/* Load A3 register */
|
/* Load A3 register */
|
||||||
worked &= write_reg( SI7210_OTP_ADDR, 0, base_addr + 3);
|
worked &= write_reg(SI7210_OTP_ADDR, 0, base_addr + 3);
|
||||||
worked &= write_reg( SI7210_OTP_CTRL, 0, OTP_READ_EN_MASK);
|
worked &= write_reg(SI7210_OTP_CTRL, 0, OTP_READ_EN_MASK);
|
||||||
worked &= read_reg( SI7210_OTP_DATA, &val);
|
worked &= read_reg(SI7210_OTP_DATA, &val);
|
||||||
worked &= write_reg( SI7210_A3, 0, val);
|
worked &= write_reg(SI7210_A3, 0, val);
|
||||||
|
|
||||||
/* Load A4 register */
|
/* Load A4 register */
|
||||||
worked &= write_reg( SI7210_OTP_ADDR, 0, base_addr + 4);
|
worked &= write_reg(SI7210_OTP_ADDR, 0, base_addr + 4);
|
||||||
worked &= write_reg( SI7210_OTP_CTRL, 0, OTP_READ_EN_MASK);
|
worked &= write_reg(SI7210_OTP_CTRL, 0, OTP_READ_EN_MASK);
|
||||||
worked &= read_reg( SI7210_OTP_DATA, &val);
|
worked &= read_reg(SI7210_OTP_DATA, &val);
|
||||||
worked &= write_reg( SI7210_A4, 0, val);
|
worked &= write_reg(SI7210_A4, 0, val);
|
||||||
|
|
||||||
/* Load A5 register */
|
/* Load A5 register */
|
||||||
worked &= write_reg( SI7210_OTP_ADDR, 0, base_addr + 5);
|
worked &= write_reg(SI7210_OTP_ADDR, 0, base_addr + 5);
|
||||||
worked &= write_reg( SI7210_OTP_CTRL, 0, OTP_READ_EN_MASK);
|
worked &= write_reg(SI7210_OTP_CTRL, 0, OTP_READ_EN_MASK);
|
||||||
worked &= read_reg( SI7210_OTP_DATA, &val);
|
worked &= read_reg(SI7210_OTP_DATA, &val);
|
||||||
worked &= write_reg( SI7210_A5, 0, val);
|
worked &= write_reg(SI7210_A5, 0, val);
|
||||||
return worked;
|
return worked;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "TipThermoModel.h"
|
#include "TipThermoModel.h"
|
||||||
#include "Settings.h"
|
|
||||||
#include "BSP.h"
|
|
||||||
#include "power.hpp"
|
|
||||||
#include "../../configuration.h"
|
#include "../../configuration.h"
|
||||||
|
#include "BSP.h"
|
||||||
|
#include "Settings.h"
|
||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
|
#include "power.hpp"
|
||||||
/*
|
/*
|
||||||
* The hardware is laid out as a non-inverting op-amp
|
* The hardware is laid out as a non-inverting op-amp
|
||||||
* There is a pullup of 39k(TS100) from the +ve input to 3.9V (1M pulup on TS100)
|
* There is a pullup of 39k(TS100) from the +ve input to 3.9V (1M pulup on TS100)
|
||||||
@@ -32,17 +32,17 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC) {
|
|||||||
// This takes the raw ADC samples, converts these to uV
|
// This takes the raw ADC samples, converts these to uV
|
||||||
// Then divides this down by the gain to convert to the uV on the input to the op-amp (A+B terminals)
|
// Then divides this down by the gain to convert to the uV on the input to the op-amp (A+B terminals)
|
||||||
// Then remove the calibration value that is stored as a tip offset
|
// Then remove the calibration value that is stored as a tip offset
|
||||||
uint32_t vddRailmVX10 = 33000; //The vreg is +-2%, but we have no higher accuracy available
|
uint32_t vddRailmVX10 = 33000; // The vreg is +-2%, but we have no higher accuracy available
|
||||||
// 4096 * 8 readings for full scale
|
// 4096 * 8 readings for full scale
|
||||||
// Convert the input ADC reading back into mV times 10 format.
|
// Convert the input ADC reading back into mV times 10 format.
|
||||||
uint32_t rawInputmVX10 = (rawADC * vddRailmVX10) / (4096 * 8);
|
uint32_t rawInputmVX10 = (rawADC * vddRailmVX10) / (4096 * 8);
|
||||||
|
|
||||||
uint32_t valueuV = rawInputmVX10 * 100; // shift into uV
|
uint32_t valueuV = rawInputmVX10 * 100; // shift into uV
|
||||||
//Now to divide this down by the gain
|
// Now to divide this down by the gain
|
||||||
valueuV /= OP_AMP_GAIN_STAGE;
|
valueuV /= OP_AMP_GAIN_STAGE;
|
||||||
|
|
||||||
if (systemSettings.CalibrationOffset) {
|
if (systemSettings.CalibrationOffset) {
|
||||||
//Remove uV tipOffset
|
// Remove uV tipOffset
|
||||||
if (valueuV >= systemSettings.CalibrationOffset)
|
if (valueuV >= systemSettings.CalibrationOffset)
|
||||||
valueuV -= systemSettings.CalibrationOffset;
|
valueuV -= systemSettings.CalibrationOffset;
|
||||||
else
|
else
|
||||||
@@ -52,27 +52,22 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC) {
|
|||||||
return valueuV;
|
return valueuV;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t TipThermoModel::convertTipRawADCToDegC(uint16_t rawADC) {
|
uint32_t TipThermoModel::convertTipRawADCToDegC(uint16_t rawADC) { return convertuVToDegC(convertTipRawADCTouV(rawADC)); }
|
||||||
return convertuVToDegC(convertTipRawADCTouV(rawADC));
|
|
||||||
}
|
|
||||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||||
uint32_t TipThermoModel::convertTipRawADCToDegF(uint16_t rawADC) {
|
uint32_t TipThermoModel::convertTipRawADCToDegF(uint16_t rawADC) { return convertuVToDegF(convertTipRawADCTouV(rawADC)); }
|
||||||
return convertuVToDegF(convertTipRawADCTouV(rawADC));
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Table that is designed to be walked to find the best sample for the lookup
|
// Table that is designed to be walked to find the best sample for the lookup
|
||||||
|
|
||||||
//Extrapolate between two points
|
// Extrapolate between two points
|
||||||
// [x1, y1] = point 1
|
// [x1, y1] = point 1
|
||||||
// [x2, y2] = point 2
|
// [x2, y2] = point 2
|
||||||
// x = input value
|
// x = input value
|
||||||
// output is x's interpolated y value
|
// output is x's interpolated y value
|
||||||
int32_t LinearInterpolate(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x) {
|
int32_t LinearInterpolate(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x) { return y1 + (((((x - x1) * 1000) / (x2 - x1)) * (y2 - y1))) / 1000; }
|
||||||
return y1 + (((((x - x1) * 1000) / (x2 - x1)) * (y2 - y1))) / 1000;
|
|
||||||
}
|
|
||||||
#ifdef TEMP_uV_LOOKUP_HAKKO
|
#ifdef TEMP_uV_LOOKUP_HAKKO
|
||||||
const uint16_t uVtoDegC[] = { //
|
const uint16_t uVtoDegC[] = {
|
||||||
|
//
|
||||||
//
|
//
|
||||||
0, 0, //
|
0, 0, //
|
||||||
266, 10, //
|
266, 10, //
|
||||||
@@ -126,71 +121,72 @@ const uint16_t uVtoDegC[] = { //
|
|||||||
12337, 490, //
|
12337, 490, //
|
||||||
12575, 500, //
|
12575, 500, //
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TEMP_uV_LOOKUP_TS80
|
#ifdef TEMP_uV_LOOKUP_TS80
|
||||||
|
|
||||||
const uint16_t uVtoDegC[] = { //
|
const uint16_t uVtoDegC[] = {
|
||||||
//
|
//
|
||||||
530 , 0, //
|
//
|
||||||
1282 , 10, //
|
530, 0, //
|
||||||
2034 , 20, //
|
1282, 10, //
|
||||||
2786 , 30, //
|
2034, 20, //
|
||||||
3538 , 40, //
|
2786, 30, //
|
||||||
4290 , 50, //
|
3538, 40, //
|
||||||
5043 , 60, //
|
4290, 50, //
|
||||||
5795 , 70, //
|
5043, 60, //
|
||||||
6547 , 80, //
|
5795, 70, //
|
||||||
7299 , 90, //
|
6547, 80, //
|
||||||
8051 , 100, //
|
7299, 90, //
|
||||||
8803 , 110, //
|
8051, 100, //
|
||||||
9555 , 120, //
|
8803, 110, //
|
||||||
10308 , 130, //
|
9555, 120, //
|
||||||
11060 , 140, //
|
10308, 130, //
|
||||||
11812 , 150, //
|
11060, 140, //
|
||||||
12564 , 160, //
|
11812, 150, //
|
||||||
13316 , 170, //
|
12564, 160, //
|
||||||
14068 , 180, //
|
13316, 170, //
|
||||||
14820 , 190, //
|
14068, 180, //
|
||||||
15573 , 200, //
|
14820, 190, //
|
||||||
16325 , 210, //
|
15573, 200, //
|
||||||
17077 , 220, //
|
16325, 210, //
|
||||||
17829 , 230, //
|
17077, 220, //
|
||||||
18581 , 240, //
|
17829, 230, //
|
||||||
19333 , 250, //
|
18581, 240, //
|
||||||
20085 , 260, //
|
19333, 250, //
|
||||||
20838 , 270, //
|
20085, 260, //
|
||||||
21590 , 280, //
|
20838, 270, //
|
||||||
22342 , 290, //
|
21590, 280, //
|
||||||
23094 , 300, //
|
22342, 290, //
|
||||||
23846 , 310, //
|
23094, 300, //
|
||||||
24598 , 320, //
|
23846, 310, //
|
||||||
25350 , 330, //
|
24598, 320, //
|
||||||
26103 , 340, //
|
25350, 330, //
|
||||||
26855 , 350, //
|
26103, 340, //
|
||||||
27607 , 360, //
|
26855, 350, //
|
||||||
28359 , 370, //
|
27607, 360, //
|
||||||
29111 , 380, //
|
28359, 370, //
|
||||||
29863 , 390, //
|
29111, 380, //
|
||||||
30615 , 400, //
|
29863, 390, //
|
||||||
31368 , 410, //
|
30615, 400, //
|
||||||
32120 , 420, //
|
31368, 410, //
|
||||||
32872 , 430, //
|
32120, 420, //
|
||||||
33624 , 440, //
|
32872, 430, //
|
||||||
34376 , 450, //
|
33624, 440, //
|
||||||
35128 , 460, //
|
34376, 450, //
|
||||||
35880 , 470, //
|
35128, 460, //
|
||||||
36632 , 480, //
|
35880, 470, //
|
||||||
37385 , 490, //
|
36632, 480, //
|
||||||
38137 , 500, //
|
37385, 490, //
|
||||||
};
|
38137, 500, //
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
|
uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
|
||||||
if (tipuVDelta) {
|
if (tipuVDelta) {
|
||||||
int noItems = sizeof(uVtoDegC) / (2 * sizeof(uint16_t));
|
int noItems = sizeof(uVtoDegC) / (2 * sizeof(uint16_t));
|
||||||
for (int i = 1; i < (noItems - 1); i++) {
|
for (int i = 1; i < (noItems - 1); i++) {
|
||||||
//If current tip temp is less than current lookup, then this current lookup is the higher point to interpolate
|
// If current tip temp is less than current lookup, then this current lookup is the higher point to interpolate
|
||||||
if (tipuVDelta < uVtoDegC[i * 2]) {
|
if (tipuVDelta < uVtoDegC[i * 2]) {
|
||||||
return LinearInterpolate(uVtoDegC[(i - 1) * 2], uVtoDegC[((i - 1) * 2) + 1], uVtoDegC[i * 2], uVtoDegC[(i * 2) + 1], tipuVDelta);
|
return LinearInterpolate(uVtoDegC[(i - 1) * 2], uVtoDegC[((i - 1) * 2) + 1], uVtoDegC[i * 2], uVtoDegC[(i * 2) + 1], tipuVDelta);
|
||||||
}
|
}
|
||||||
@@ -201,9 +197,7 @@ uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||||
uint32_t TipThermoModel::convertuVToDegF(uint32_t tipuVDelta) {
|
uint32_t TipThermoModel::convertuVToDegF(uint32_t tipuVDelta) { return convertCtoF(convertuVToDegC(tipuVDelta)); }
|
||||||
return convertCtoF(convertuVToDegC(tipuVDelta));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t TipThermoModel::convertCtoF(uint32_t degC) {
|
uint32_t TipThermoModel::convertCtoF(uint32_t degC) {
|
||||||
//(Y °C × 9/5) + 32 =Y°F
|
//(Y °C × 9/5) + 32 =Y°F
|
||||||
@@ -221,7 +215,7 @@ uint32_t TipThermoModel::convertFtoC(uint32_t degF) {
|
|||||||
|
|
||||||
uint32_t TipThermoModel::getTipInC(bool sampleNow) {
|
uint32_t TipThermoModel::getTipInC(bool sampleNow) {
|
||||||
int32_t currentTipTempInC = TipThermoModel::convertTipRawADCToDegC(getTipRawTemp(sampleNow));
|
int32_t currentTipTempInC = TipThermoModel::convertTipRawADCToDegC(getTipRawTemp(sampleNow));
|
||||||
currentTipTempInC += getHandleTemperature() / 10; //Add handle offset
|
currentTipTempInC += getHandleTemperature() / 10; // Add handle offset
|
||||||
// Power usage indicates that our tip temp is lower than our thermocouple temp.
|
// Power usage indicates that our tip temp is lower than our thermocouple temp.
|
||||||
// I found a number that doesn't unbalance the existing PID, causing overshoot.
|
// I found a number that doesn't unbalance the existing PID, causing overshoot.
|
||||||
// This could be tuned in concert with PID parameters...
|
// This could be tuned in concert with PID parameters...
|
||||||
@@ -239,7 +233,7 @@ uint32_t TipThermoModel::getTipInF(bool sampleNow) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint32_t TipThermoModel::getTipMaxInC() {
|
uint32_t TipThermoModel::getTipMaxInC() {
|
||||||
uint32_t maximumTipTemp = TipThermoModel::convertTipRawADCToDegC(0x7FFF - (21 * 5)); //back off approx 5 deg c from ADC max
|
uint32_t maximumTipTemp = TipThermoModel::convertTipRawADCToDegC(0x7FFF - (21 * 5)); // back off approx 5 deg c from ADC max
|
||||||
maximumTipTemp += getHandleTemperature() / 10; //Add handle offset
|
maximumTipTemp += getHandleTemperature() / 10; // Add handle offset
|
||||||
return maximumTipTemp - 1;
|
return maximumTipTemp - 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,28 +7,23 @@
|
|||||||
|
|
||||||
#include "FreeRTOSHooks.h"
|
#include "FreeRTOSHooks.h"
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
void vApplicationIdleHook(void) {
|
void vApplicationIdleHook(void) { resetWatchdog(); }
|
||||||
resetWatchdog();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
|
/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
|
||||||
static StaticTask_t xIdleTaskTCBBuffer;
|
static StaticTask_t xIdleTaskTCBBuffer;
|
||||||
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];
|
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];
|
||||||
|
|
||||||
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
|
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) {
|
||||||
StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) {
|
|
||||||
*ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
|
*ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
|
||||||
*ppxIdleTaskStackBuffer = &xIdleStack[0];
|
*ppxIdleTaskStackBuffer = &xIdleStack[0];
|
||||||
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
||||||
/* place for user code */
|
/* place for user code */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed portCHAR *pcTaskName) {
|
||||||
|
(void)pxTask;
|
||||||
|
(void)pcTaskName;
|
||||||
|
|
||||||
void vApplicationStackOverflowHook(TaskHandle_t *pxTask,
|
// We dont have a good way to handle a stack overflow at this point in time
|
||||||
signed portCHAR *pcTaskName) {
|
|
||||||
(void) pxTask;
|
|
||||||
(void) pcTaskName;
|
|
||||||
|
|
||||||
// We dont have a good way to handle a stack overflow at this point in time
|
|
||||||
reboot();
|
reboot();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,9 +175,6 @@ void startQC(uint16_t divisor) {
|
|||||||
QCTries++;
|
QCTries++;
|
||||||
QCMode = QCState::NO_QC;
|
QCMode = QCState::NO_QC;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasQCNegotiated() {
|
bool hasQCNegotiated() { return QCMode == QCState::QC_3 || QCMode == QCState::QC_2; }
|
||||||
return QCMode == QCState::QC_3 || QCMode == QCState::QC_2;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,21 +9,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "Setup.h"
|
|
||||||
#include "../../configuration.h"
|
#include "../../configuration.h"
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
|
#include "Setup.h"
|
||||||
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
volatile systemSettingsType systemSettings;
|
volatile systemSettingsType systemSettings;
|
||||||
|
|
||||||
void saveSettings() {
|
void saveSettings() {
|
||||||
// First we erase the flash
|
// First we erase the flash
|
||||||
flash_save_buffer((uint8_t*) &systemSettings, sizeof(systemSettingsType));
|
flash_save_buffer((uint8_t *)&systemSettings, sizeof(systemSettingsType));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool restoreSettings() {
|
bool restoreSettings() {
|
||||||
// We read the flash
|
// We read the flash
|
||||||
flash_read_buffer((uint8_t*) &systemSettings, sizeof(systemSettingsType));
|
flash_read_buffer((uint8_t *)&systemSettings, sizeof(systemSettingsType));
|
||||||
|
|
||||||
// if the version is correct were done
|
// if the version is correct were done
|
||||||
// if not we reset and save
|
// if not we reset and save
|
||||||
@@ -49,7 +49,7 @@ uint8_t lookupVoltageLevel() {
|
|||||||
return (systemSettings.minDCVoltageCells * 33) + (33 * 2);
|
return (systemSettings.minDCVoltageCells * 33) + (33 * 2);
|
||||||
}
|
}
|
||||||
void resetSettings() {
|
void resetSettings() {
|
||||||
memset((void*) &systemSettings, 0, sizeof(systemSettingsType));
|
memset((void *)&systemSettings, 0, sizeof(systemSettingsType));
|
||||||
systemSettings.SleepTemp = SLEEP_TEMP; // Temperature the iron sleeps at - default 150.0 C
|
systemSettings.SleepTemp = SLEEP_TEMP; // Temperature the iron sleeps at - default 150.0 C
|
||||||
systemSettings.SleepTime = SLEEP_TIME; // How many seconds/minutes we wait until going
|
systemSettings.SleepTime = SLEEP_TIME; // How many seconds/minutes we wait until going
|
||||||
// to sleep - default 1 min
|
// to sleep - default 1 min
|
||||||
@@ -89,13 +89,13 @@ uint16_t lookupHallEffectThreshold() {
|
|||||||
switch (systemSettings.hallEffectSensitivity) {
|
switch (systemSettings.hallEffectSensitivity) {
|
||||||
case 0:
|
case 0:
|
||||||
return 0;
|
return 0;
|
||||||
case 1: //Low
|
case 1: // Low
|
||||||
return 1000;
|
return 1000;
|
||||||
case 2: //Medium
|
case 2: // Medium
|
||||||
return 500;
|
return 500;
|
||||||
case 3: //High
|
case 3: // High
|
||||||
return 100;
|
return 100;
|
||||||
default:
|
default:
|
||||||
return 0; //Off
|
return 0; // Off
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,14 +6,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gui.hpp"
|
#include "gui.hpp"
|
||||||
|
#include "../../configuration.h"
|
||||||
|
#include "Buttons.hpp"
|
||||||
|
#include "TipThermoModel.h"
|
||||||
#include "Translation.h"
|
#include "Translation.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
#include "TipThermoModel.h"
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
#include "../../configuration.h"
|
|
||||||
#include "Buttons.hpp"
|
|
||||||
|
|
||||||
void gui_Menu(const menuitem *menu);
|
void gui_Menu(const menuitem *menu);
|
||||||
|
|
||||||
@@ -59,8 +59,8 @@ static bool settings_setResetSettings(void);
|
|||||||
static void settings_displayResetSettings(void);
|
static void settings_displayResetSettings(void);
|
||||||
static bool settings_setCalibrate(void);
|
static bool settings_setCalibrate(void);
|
||||||
static void settings_displayCalibrate(void);
|
static void settings_displayCalibrate(void);
|
||||||
//static bool settings_setTipGain(void);
|
// static bool settings_setTipGain(void);
|
||||||
//static void settings_displayTipGain(void);
|
// static void settings_displayTipGain(void);
|
||||||
static bool settings_setCalibrateVIN(void);
|
static bool settings_setCalibrateVIN(void);
|
||||||
static void settings_displayCalibrateVIN(void);
|
static void settings_displayCalibrateVIN(void);
|
||||||
static void settings_displayReverseButtonTempChangeEnabled(void);
|
static void settings_displayReverseButtonTempChangeEnabled(void);
|
||||||
@@ -122,7 +122,7 @@ static bool settings_enterAdvancedMenu(void);
|
|||||||
* Reset Settings
|
* Reset Settings
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
const menuitem rootSettingsMenu[] {
|
const menuitem rootSettingsMenu[]{
|
||||||
/*
|
/*
|
||||||
* Power Source
|
* Power Source
|
||||||
* Soldering Menu
|
* Soldering Menu
|
||||||
@@ -132,32 +132,32 @@ const menuitem rootSettingsMenu[] {
|
|||||||
* Exit
|
* Exit
|
||||||
*/
|
*/
|
||||||
#ifdef POW_DC
|
#ifdef POW_DC
|
||||||
{ (const char *) SettingsDescriptions[0], settings_setInputVRange, settings_displayInputVRange }, /*Voltage input*/
|
{(const char *)SettingsDescriptions[0], settings_setInputVRange, settings_displayInputVRange}, /*Voltage input*/
|
||||||
#endif
|
#endif
|
||||||
#ifdef POW_QC
|
#ifdef POW_QC
|
||||||
{ (const char *) SettingsDescriptions[19], settings_setQCInputV, settings_displayQCInputV }, /*Voltage input*/
|
{(const char *)SettingsDescriptions[19], settings_setQCInputV, settings_displayQCInputV}, /*Voltage input*/
|
||||||
#endif
|
#endif
|
||||||
{ (const char *) NULL, settings_enterSolderingMenu, settings_displaySolderingMenu }, /*Soldering*/
|
{(const char *)NULL, settings_enterSolderingMenu, settings_displaySolderingMenu}, /*Soldering*/
|
||||||
{ (const char *) NULL, settings_enterPowerMenu, settings_displayPowerMenu }, /*Sleep Options Menu*/
|
{(const char *)NULL, settings_enterPowerMenu, settings_displayPowerMenu}, /*Sleep Options Menu*/
|
||||||
{ (const char *) NULL, settings_enterUIMenu, settings_displayUIMenu }, /*UI Menu*/
|
{(const char *)NULL, settings_enterUIMenu, settings_displayUIMenu}, /*UI Menu*/
|
||||||
{ (const char *) NULL, settings_enterAdvancedMenu, settings_displayAdvancedMenu }, /*Advanced Menu*/
|
{(const char *)NULL, settings_enterAdvancedMenu, settings_displayAdvancedMenu}, /*Advanced Menu*/
|
||||||
{ NULL, NULL, NULL } // end of menu marker. DO NOT REMOVE
|
{NULL, NULL, NULL} // end of menu marker. DO NOT REMOVE
|
||||||
};
|
};
|
||||||
|
|
||||||
const menuitem solderingMenu[] = {
|
const menuitem solderingMenu[] = {
|
||||||
/*
|
/*
|
||||||
* Boost Mode Enabled
|
* Boost Mode Enabled
|
||||||
* Boost Mode Temp
|
* Boost Mode Temp
|
||||||
* Auto Start
|
* Auto Start
|
||||||
* Temp change short step
|
* Temp change short step
|
||||||
* Temp change long step
|
* Temp change long step
|
||||||
*/
|
*/
|
||||||
{ (const char *) SettingsDescriptions[8], settings_setBoostTemp, settings_displayBoostTemp }, /*Boost Temp*/
|
{(const char *)SettingsDescriptions[8], settings_setBoostTemp, settings_displayBoostTemp}, /*Boost Temp*/
|
||||||
{ (const char *) SettingsDescriptions[9], settings_setAutomaticStartMode, settings_displayAutomaticStartMode }, /*Auto start*/
|
{(const char *)SettingsDescriptions[9], settings_setAutomaticStartMode, settings_displayAutomaticStartMode}, /*Auto start*/
|
||||||
{ (const char *) SettingsDescriptions[22], settings_setTempChangeShortStep, settings_displayTempChangeShortStep }, /*Temp change short step*/
|
{(const char *)SettingsDescriptions[22], settings_setTempChangeShortStep, settings_displayTempChangeShortStep}, /*Temp change short step*/
|
||||||
{ (const char *) SettingsDescriptions[23], settings_setTempChangeLongStep, settings_displayTempChangeLongStep }, /*Temp change long step*/
|
{(const char *)SettingsDescriptions[23], settings_setTempChangeLongStep, settings_displayTempChangeLongStep}, /*Temp change long step*/
|
||||||
{ (const char *) SettingsDescriptions[27], settings_setLockingMode, settings_displayLockingMode }, /*Locking Mode*/
|
{(const char *)SettingsDescriptions[27], settings_setLockingMode, settings_displayLockingMode}, /*Locking Mode*/
|
||||||
{ NULL, NULL, NULL } // end of menu marker. DO NOT REMOVE
|
{NULL, NULL, NULL} // end of menu marker. DO NOT REMOVE
|
||||||
};
|
};
|
||||||
const menuitem UIMenu[] = {
|
const menuitem UIMenu[] = {
|
||||||
/*
|
/*
|
||||||
@@ -169,34 +169,33 @@ const menuitem UIMenu[] = {
|
|||||||
* Reverse Temp change buttons + -
|
* Reverse Temp change buttons + -
|
||||||
*/
|
*/
|
||||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||||
{ (const char *)SettingsDescriptions[5], settings_setTempF,
|
{(const char *)SettingsDescriptions[5], settings_setTempF, settings_displayTempF}, /* Temperature units*/
|
||||||
settings_displayTempF}, /* Temperature units*/
|
|
||||||
#endif
|
#endif
|
||||||
{ (const char *) SettingsDescriptions[7], settings_setDisplayRotation, settings_displayDisplayRotation }, /*Display Rotation*/
|
{(const char *)SettingsDescriptions[7], settings_setDisplayRotation, settings_displayDisplayRotation}, /*Display Rotation*/
|
||||||
{ (const char *) SettingsDescriptions[10], settings_setCoolingBlinkEnabled, settings_displayCoolingBlinkEnabled }, /*Cooling blink warning*/
|
{(const char *)SettingsDescriptions[10], settings_setCoolingBlinkEnabled, settings_displayCoolingBlinkEnabled}, /*Cooling blink warning*/
|
||||||
{ (const char *) SettingsDescriptions[15], settings_setScrollSpeed, settings_displayScrollSpeed }, /*Scroll Speed for descriptions*/
|
{(const char *)SettingsDescriptions[15], settings_setScrollSpeed, settings_displayScrollSpeed}, /*Scroll Speed for descriptions*/
|
||||||
{ (const char *) SettingsDescriptions[21], settings_setReverseButtonTempChangeEnabled, settings_displayReverseButtonTempChangeEnabled }, /* Reverse Temp change buttons + - */
|
{(const char *)SettingsDescriptions[21], settings_setReverseButtonTempChangeEnabled, settings_displayReverseButtonTempChangeEnabled}, /* Reverse Temp change buttons + - */
|
||||||
{ NULL, NULL, NULL } // end of menu marker. DO NOT REMOVE
|
{NULL, NULL, NULL} // end of menu marker. DO NOT REMOVE
|
||||||
};
|
};
|
||||||
const menuitem PowerMenu[] = {
|
const menuitem PowerMenu[] = {
|
||||||
/*
|
/*
|
||||||
* Sleep Temp
|
* Sleep Temp
|
||||||
* Sleep Time
|
* Sleep Time
|
||||||
* Shutdown Time
|
* Shutdown Time
|
||||||
* Motion Sensitivity
|
* Motion Sensitivity
|
||||||
*/
|
*/
|
||||||
{ (const char *) SettingsDescriptions[1], settings_setSleepTemp, settings_displaySleepTemp }, /*Sleep Temp*/
|
{(const char *)SettingsDescriptions[1], settings_setSleepTemp, settings_displaySleepTemp}, /*Sleep Temp*/
|
||||||
{ (const char *) SettingsDescriptions[2], settings_setSleepTime, settings_displaySleepTime }, /*Sleep Time*/
|
{(const char *)SettingsDescriptions[2], settings_setSleepTime, settings_displaySleepTime}, /*Sleep Time*/
|
||||||
{ (const char *) SettingsDescriptions[3], settings_setShutdownTime, settings_displayShutdownTime }, /*Shutdown Time*/
|
{(const char *)SettingsDescriptions[3], settings_setShutdownTime, settings_displayShutdownTime}, /*Shutdown Time*/
|
||||||
{ (const char *) SettingsDescriptions[4], settings_setSensitivity, settings_displaySensitivity }, /* Motion Sensitivity*/
|
{(const char *)SettingsDescriptions[4], settings_setSensitivity, settings_displaySensitivity}, /* Motion Sensitivity*/
|
||||||
#ifdef HALL_SENSOR
|
#ifdef HALL_SENSOR
|
||||||
{ (const char *) SettingsDescriptions[26], settings_setHallEffect, settings_displayHallEffect }, /* HallEffect Sensitivity*/
|
{(const char *)SettingsDescriptions[26], settings_setHallEffect, settings_displayHallEffect}, /* HallEffect Sensitivity*/
|
||||||
#endif
|
#endif
|
||||||
{ NULL, NULL, NULL } // end of menu marker. DO NOT REMOVE
|
{NULL, NULL, NULL} // end of menu marker. DO NOT REMOVE
|
||||||
};
|
};
|
||||||
const menuitem advancedMenu[] = {
|
const menuitem advancedMenu[] = {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Power limit
|
* Power limit
|
||||||
* Detailed IDLE
|
* Detailed IDLE
|
||||||
* Detailed Soldering
|
* Detailed Soldering
|
||||||
@@ -205,15 +204,15 @@ const menuitem advancedMenu[] = {
|
|||||||
* Reset Settings
|
* Reset Settings
|
||||||
* Power Pulse
|
* Power Pulse
|
||||||
*/
|
*/
|
||||||
{ (const char *) SettingsDescriptions[20], settings_setPowerLimit, settings_displayPowerLimit }, /*Power limit*/
|
{(const char *)SettingsDescriptions[20], settings_setPowerLimit, settings_displayPowerLimit}, /*Power limit*/
|
||||||
{ (const char *) SettingsDescriptions[6], settings_setAdvancedIDLEScreens, settings_displayAdvancedIDLEScreens }, /* Advanced idle screen*/
|
{(const char *)SettingsDescriptions[6], settings_setAdvancedIDLEScreens, settings_displayAdvancedIDLEScreens}, /* Advanced idle screen*/
|
||||||
{ (const char *) SettingsDescriptions[14], settings_setAdvancedSolderingScreens, settings_displayAdvancedSolderingScreens }, /* Advanced soldering screen*/
|
{(const char *)SettingsDescriptions[14], settings_setAdvancedSolderingScreens, settings_displayAdvancedSolderingScreens}, /* Advanced soldering screen*/
|
||||||
{ (const char *) SettingsDescriptions[12], settings_setResetSettings, settings_displayResetSettings }, /*Resets settings*/
|
{(const char *)SettingsDescriptions[12], settings_setResetSettings, settings_displayResetSettings}, /*Resets settings*/
|
||||||
{ (const char *) SettingsDescriptions[11], settings_setCalibrate, settings_displayCalibrate }, /*Calibrate tip*/
|
{(const char *)SettingsDescriptions[11], settings_setCalibrate, settings_displayCalibrate}, /*Calibrate tip*/
|
||||||
{ (const char *) SettingsDescriptions[13], settings_setCalibrateVIN, settings_displayCalibrateVIN }, /*Voltage input cal*/
|
{(const char *)SettingsDescriptions[13], settings_setCalibrateVIN, settings_displayCalibrateVIN}, /*Voltage input cal*/
|
||||||
{ (const char *) SettingsDescriptions[24], settings_setPowerPulse, settings_displayPowerPulse }, /*Power Pulse adjustment */
|
{(const char *)SettingsDescriptions[24], settings_setPowerPulse, settings_displayPowerPulse}, /*Power Pulse adjustment */
|
||||||
//{ (const char *) SettingsDescriptions[25], settings_setTipGain, settings_displayTipGain }, /*TipGain*/
|
//{ (const char *) SettingsDescriptions[25], settings_setTipGain, settings_displayTipGain }, /*TipGain*/
|
||||||
{ NULL, NULL, NULL } // end of menu marker. DO NOT REMOVE
|
{NULL, NULL, NULL} // end of menu marker. DO NOT REMOVE
|
||||||
};
|
};
|
||||||
|
|
||||||
static void printShortDescriptionDoubleLine(uint32_t shortDescIndex) {
|
static void printShortDescriptionDoubleLine(uint32_t shortDescIndex) {
|
||||||
@@ -319,7 +318,7 @@ static bool settings_setQCInputV(void) {
|
|||||||
|
|
||||||
static void settings_displayQCInputV(void) {
|
static void settings_displayQCInputV(void) {
|
||||||
printShortDescription(19, 5);
|
printShortDescription(19, 5);
|
||||||
//0 = 9V, 1=12V, 2=20V (Fixed Voltages)
|
// 0 = 9V, 1=12V, 2=20V (Fixed Voltages)
|
||||||
// These are only used in QC modes
|
// These are only used in QC modes
|
||||||
switch (systemSettings.QCIdealVoltage) {
|
switch (systemSettings.QCIdealVoltage) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -343,14 +342,12 @@ static void settings_displayQCInputV(void) {
|
|||||||
static bool settings_setSleepTemp(void) {
|
static bool settings_setSleepTemp(void) {
|
||||||
// If in C, 10 deg, if in F 20 deg
|
// If in C, 10 deg, if in F 20 deg
|
||||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||||
if (systemSettings.temperatureInF)
|
if (systemSettings.temperatureInF) {
|
||||||
{
|
|
||||||
systemSettings.SleepTemp += 20;
|
systemSettings.SleepTemp += 20;
|
||||||
if (systemSettings.SleepTemp > 580)
|
if (systemSettings.SleepTemp > 580)
|
||||||
systemSettings.SleepTemp = 60;
|
systemSettings.SleepTemp = 60;
|
||||||
return systemSettings.SleepTemp == 580;
|
return systemSettings.SleepTemp == 580;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
systemSettings.SleepTemp += 10;
|
systemSettings.SleepTemp += 10;
|
||||||
@@ -409,20 +406,15 @@ static void settings_displayShutdownTime(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||||
static bool settings_setTempF(void)
|
static bool settings_setTempF(void) {
|
||||||
{
|
|
||||||
systemSettings.temperatureInF = !systemSettings.temperatureInF;
|
systemSettings.temperatureInF = !systemSettings.temperatureInF;
|
||||||
if (systemSettings.temperatureInF)
|
if (systemSettings.temperatureInF) {
|
||||||
{
|
|
||||||
// Change sleep, boost and soldering temps to the F equiv
|
// Change sleep, boost and soldering temps to the F equiv
|
||||||
// C to F == F= ( (C*9) +160)/5
|
// C to F == F= ( (C*9) +160)/5
|
||||||
systemSettings.BoostTemp = ((systemSettings.BoostTemp * 9) + 160) / 5;
|
systemSettings.BoostTemp = ((systemSettings.BoostTemp * 9) + 160) / 5;
|
||||||
systemSettings.SolderingTemp =
|
systemSettings.SolderingTemp = ((systemSettings.SolderingTemp * 9) + 160) / 5;
|
||||||
((systemSettings.SolderingTemp * 9) + 160) / 5;
|
|
||||||
systemSettings.SleepTemp = ((systemSettings.SleepTemp * 9) + 160) / 5;
|
systemSettings.SleepTemp = ((systemSettings.SleepTemp * 9) + 160) / 5;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// Change sleep, boost and soldering temps to the C equiv
|
// Change sleep, boost and soldering temps to the C equiv
|
||||||
// F->C == C = ((F-32)*5)/9
|
// F->C == C = ((F-32)*5)/9
|
||||||
systemSettings.BoostTemp = ((systemSettings.BoostTemp - 32) * 5) / 9;
|
systemSettings.BoostTemp = ((systemSettings.BoostTemp - 32) * 5) / 9;
|
||||||
@@ -439,8 +431,7 @@ static bool settings_setTempF(void)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void settings_displayTempF(void)
|
static void settings_displayTempF(void) {
|
||||||
{
|
|
||||||
printShortDescription(5, 7);
|
printShortDescription(5, 7);
|
||||||
|
|
||||||
OLED::print((systemSettings.temperatureInF) ? SymbolDegF : SymbolDegC);
|
OLED::print((systemSettings.temperatureInF) ? SymbolDegF : SymbolDegC);
|
||||||
@@ -550,24 +541,18 @@ static void settings_displayDisplayRotation(void) {
|
|||||||
|
|
||||||
static bool settings_setBoostTemp(void) {
|
static bool settings_setBoostTemp(void) {
|
||||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||||
if (systemSettings.temperatureInF)
|
if (systemSettings.temperatureInF) {
|
||||||
{
|
if (systemSettings.BoostTemp == 0) {
|
||||||
if (systemSettings.BoostTemp == 0)
|
|
||||||
{
|
|
||||||
systemSettings.BoostTemp = 480; // loop back at 480
|
systemSettings.BoostTemp = 480; // loop back at 480
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
systemSettings.BoostTemp += 20; // Go up 20F at a time
|
systemSettings.BoostTemp += 20; // Go up 20F at a time
|
||||||
}
|
}
|
||||||
|
|
||||||
if (systemSettings.BoostTemp > 850)
|
if (systemSettings.BoostTemp > 850) {
|
||||||
{
|
|
||||||
systemSettings.BoostTemp = 0; // jump to off
|
systemSettings.BoostTemp = 0; // jump to off
|
||||||
}
|
}
|
||||||
return systemSettings.BoostTemp == 840;
|
return systemSettings.BoostTemp == 840;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (systemSettings.BoostTemp == 0) {
|
if (systemSettings.BoostTemp == 0) {
|
||||||
@@ -576,7 +561,7 @@ static bool settings_setBoostTemp(void) {
|
|||||||
systemSettings.BoostTemp += 10; // Go up 10C at a time
|
systemSettings.BoostTemp += 10; // Go up 10C at a time
|
||||||
}
|
}
|
||||||
if (systemSettings.BoostTemp > 450) {
|
if (systemSettings.BoostTemp > 450) {
|
||||||
systemSettings.BoostTemp = 0; //Go to off state
|
systemSettings.BoostTemp = 0; // Go to off state
|
||||||
}
|
}
|
||||||
return systemSettings.BoostTemp == 450;
|
return systemSettings.BoostTemp == 450;
|
||||||
}
|
}
|
||||||
@@ -630,13 +615,13 @@ static void settings_displayLockingMode(void) {
|
|||||||
|
|
||||||
switch (systemSettings.lockingMode) {
|
switch (systemSettings.lockingMode) {
|
||||||
case 0:
|
case 0:
|
||||||
OLED::print (SettingLockDisableChar);
|
OLED::print(SettingLockDisableChar);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
OLED::print (SettingLockBoostChar);
|
OLED::print(SettingLockBoostChar);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
OLED::print (SettingLockFullChar);
|
OLED::print(SettingLockFullChar);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
OLED::print(SettingLockDisableChar);
|
OLED::print(SettingLockDisableChar);
|
||||||
@@ -669,9 +654,7 @@ static bool settings_setResetSettings(void) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void settings_displayResetSettings(void) {
|
static void settings_displayResetSettings(void) { printShortDescription(12, 7); }
|
||||||
printShortDescription(12, 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setTipOffset() {
|
static void setTipOffset() {
|
||||||
systemSettings.CalibrationOffset = 0;
|
systemSettings.CalibrationOffset = 0;
|
||||||
@@ -702,8 +685,8 @@ static void setTipOffset() {
|
|||||||
osDelay(1200);
|
osDelay(1200);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Provide the user the option to tune their own tip if custom is selected
|
// Provide the user the option to tune their own tip if custom is selected
|
||||||
//If not only do single point tuning as per usual
|
// If not only do single point tuning as per usual
|
||||||
static bool settings_setCalibrate(void) {
|
static bool settings_setCalibrate(void) {
|
||||||
|
|
||||||
if (userConfirmation(SettingsCalibrationWarning)) {
|
if (userConfirmation(SettingsCalibrationWarning)) {
|
||||||
@@ -714,9 +697,7 @@ static bool settings_setCalibrate(void) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void settings_displayCalibrate(void) {
|
static void settings_displayCalibrate(void) { printShortDescription(11, 5); }
|
||||||
printShortDescription(11, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool settings_setCalibrateVIN(void) {
|
static bool settings_setCalibrateVIN(void) {
|
||||||
// Jump to the voltage calibration subscreen
|
// Jump to the voltage calibration subscreen
|
||||||
@@ -759,12 +740,9 @@ static bool settings_setCalibrateVIN(void) {
|
|||||||
|
|
||||||
// Cap to sensible values
|
// Cap to sensible values
|
||||||
#if defined(MODEL_TS80) + defined(MODEL_TS80P) > 0
|
#if defined(MODEL_TS80) + defined(MODEL_TS80P) > 0
|
||||||
if (systemSettings.voltageDiv < 500)
|
if (systemSettings.voltageDiv < 500) {
|
||||||
{
|
|
||||||
systemSettings.voltageDiv = 500;
|
systemSettings.voltageDiv = 500;
|
||||||
}
|
} else if (systemSettings.voltageDiv > 900) {
|
||||||
else if (systemSettings.voltageDiv > 900)
|
|
||||||
{
|
|
||||||
systemSettings.voltageDiv = 900;
|
systemSettings.voltageDiv = 900;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -778,7 +756,7 @@ static bool settings_setCalibrateVIN(void) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
//static bool settings_setTipGain(void) {
|
// static bool settings_setTipGain(void) {
|
||||||
// OLED::setFont(0);
|
// OLED::setFont(0);
|
||||||
// OLED::clearScreen();
|
// OLED::clearScreen();
|
||||||
//
|
//
|
||||||
@@ -821,7 +799,7 @@ static bool settings_setCalibrateVIN(void) {
|
|||||||
// return false;
|
// return false;
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//static void settings_displayTipGain(void) {
|
// static void settings_displayTipGain(void) {
|
||||||
// printShortDescription(25, 5);
|
// printShortDescription(25, 5);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
@@ -897,7 +875,7 @@ static void settings_displayHallEffect(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
static bool settings_setHallEffect(void) {
|
static bool settings_setHallEffect(void) {
|
||||||
//To keep life simpler for now, we have a few preset sensitivity levels
|
// To keep life simpler for now, we have a few preset sensitivity levels
|
||||||
// Off, Low, Medium, High
|
// Off, Low, Medium, High
|
||||||
systemSettings.hallEffectSensitivity++;
|
systemSettings.hallEffectSensitivity++;
|
||||||
systemSettings.hallEffectSensitivity %= 4;
|
systemSettings.hallEffectSensitivity %= 4;
|
||||||
@@ -916,33 +894,23 @@ static void displayMenu(size_t index) {
|
|||||||
OLED::drawArea(96 - 16 - 2, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * index]));
|
OLED::drawArea(96 - 16 - 2, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * index]));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void settings_displayCalibrateVIN(void) {
|
static void settings_displayCalibrateVIN(void) { printShortDescription(13, 5); }
|
||||||
printShortDescription(13, 5);
|
static void settings_displaySolderingMenu(void) { displayMenu(0); }
|
||||||
}
|
|
||||||
static void settings_displaySolderingMenu(void) {
|
|
||||||
displayMenu(0);
|
|
||||||
}
|
|
||||||
static bool settings_enterSolderingMenu(void) {
|
static bool settings_enterSolderingMenu(void) {
|
||||||
gui_Menu(solderingMenu);
|
gui_Menu(solderingMenu);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
static void settings_displayPowerMenu(void) {
|
static void settings_displayPowerMenu(void) { displayMenu(1); }
|
||||||
displayMenu(1);
|
|
||||||
}
|
|
||||||
static bool settings_enterPowerMenu(void) {
|
static bool settings_enterPowerMenu(void) {
|
||||||
gui_Menu(PowerMenu);
|
gui_Menu(PowerMenu);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
static void settings_displayUIMenu(void) {
|
static void settings_displayUIMenu(void) { displayMenu(2); }
|
||||||
displayMenu(2);
|
|
||||||
}
|
|
||||||
static bool settings_enterUIMenu(void) {
|
static bool settings_enterUIMenu(void) {
|
||||||
gui_Menu(UIMenu);
|
gui_Menu(UIMenu);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
static void settings_displayAdvancedMenu(void) {
|
static void settings_displayAdvancedMenu(void) { displayMenu(3); }
|
||||||
displayMenu(3);
|
|
||||||
}
|
|
||||||
static bool settings_enterAdvancedMenu(void) {
|
static bool settings_enterAdvancedMenu(void) {
|
||||||
gui_Menu(advancedMenu);
|
gui_Menu(advancedMenu);
|
||||||
return false;
|
return false;
|
||||||
@@ -1004,8 +972,7 @@ void gui_Menu(const menuitem *menu) {
|
|||||||
if (descriptionStart == 0)
|
if (descriptionStart == 0)
|
||||||
descriptionStart = xTaskGetTickCount();
|
descriptionStart = xTaskGetTickCount();
|
||||||
// lower the value - higher the speed
|
// lower the value - higher the speed
|
||||||
int16_t descriptionWidth =
|
int16_t descriptionWidth = FONT_12_WIDTH * (strlen(menu[currentScreen].description) + 7);
|
||||||
FONT_12_WIDTH * (strlen(menu[currentScreen].description) + 7);
|
|
||||||
int16_t descriptionOffset = ((xTaskGetTickCount() - descriptionStart) / (systemSettings.descriptionScrollSpeed == 1 ? 10 : 20));
|
int16_t descriptionOffset = ((xTaskGetTickCount() - descriptionStart) / (systemSettings.descriptionScrollSpeed == 1 ? 10 : 20));
|
||||||
descriptionOffset %= descriptionWidth; // Roll around at the end
|
descriptionOffset %= descriptionWidth; // Roll around at the end
|
||||||
if (lastOffset != descriptionOffset) {
|
if (lastOffset != descriptionOffset) {
|
||||||
@@ -1060,8 +1027,7 @@ void gui_Menu(const menuitem *menu) {
|
|||||||
descriptionStart = 0;
|
descriptionStart = 0;
|
||||||
break;
|
break;
|
||||||
case BUTTON_F_LONG:
|
case BUTTON_F_LONG:
|
||||||
if ((int) (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration) >
|
if ((int)(xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration) > PRESS_ACCEL_INTERVAL_MAX) {
|
||||||
PRESS_ACCEL_INTERVAL_MAX) {
|
|
||||||
if ((lastValue = menu[currentScreen].incrementHandler()))
|
if ((lastValue = menu[currentScreen].incrementHandler()))
|
||||||
autoRepeatTimer = 1000;
|
autoRepeatTimer = 1000;
|
||||||
else
|
else
|
||||||
@@ -1075,8 +1041,7 @@ void gui_Menu(const menuitem *menu) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BUTTON_B_LONG:
|
case BUTTON_B_LONG:
|
||||||
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration >
|
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) {
|
||||||
PRESS_ACCEL_INTERVAL_MAX) {
|
|
||||||
currentScreen++;
|
currentScreen++;
|
||||||
autoRepeatTimer = xTaskGetTickCount();
|
autoRepeatTimer = xTaskGetTickCount();
|
||||||
descriptionStart = 0;
|
descriptionStart = 0;
|
||||||
@@ -1089,10 +1054,8 @@ void gui_Menu(const menuitem *menu) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) <
|
if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < PRESS_ACCEL_INTERVAL_MIN) {
|
||||||
PRESS_ACCEL_INTERVAL_MIN) {
|
autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN;
|
||||||
autoRepeatAcceleration =
|
|
||||||
PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lcdRefresh) {
|
if (lcdRefresh) {
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include <main.hpp>
|
|
||||||
#include "LIS2DH12.hpp"
|
#include "LIS2DH12.hpp"
|
||||||
#include <MMA8652FC.hpp>
|
|
||||||
#include <power.hpp>
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
#include <MMA8652FC.hpp>
|
||||||
|
#include <main.hpp>
|
||||||
|
#include <power.hpp>
|
||||||
uint8_t DetectedAccelerometerVersion = 0;
|
uint8_t DetectedAccelerometerVersion = 0;
|
||||||
bool settingsWereReset = false;
|
bool settingsWereReset = false;
|
||||||
// FreeRTOS variables
|
// FreeRTOS variables
|
||||||
@@ -66,6 +66,5 @@ int main(void) {
|
|||||||
/* Start scheduler */
|
/* Start scheduler */
|
||||||
osKernelStart();
|
osKernelStart();
|
||||||
/* We should never get here as control is now taken by the scheduler */
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
for (;;) {
|
for (;;) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
* Authors: Ben V. Brown, David Hilton <- Mostly David
|
* Authors: Ben V. Brown, David Hilton <- Mostly David
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <power.hpp>
|
|
||||||
#include <Settings.h>
|
|
||||||
#include <BSP.h>
|
#include <BSP.h>
|
||||||
|
#include <Settings.h>
|
||||||
|
#include <power.hpp>
|
||||||
|
|
||||||
static int32_t PWMToX10Watts(uint8_t pwm, uint8_t sample);
|
static int32_t PWMToX10Watts(uint8_t pwm, uint8_t sample);
|
||||||
|
|
||||||
expMovingAverage<uint32_t, wattHistoryFilter> x10WattHistory = { 0 };
|
expMovingAverage<uint32_t, wattHistoryFilter> x10WattHistory = {0};
|
||||||
|
|
||||||
int32_t tempToX10Watts(int32_t rawTemp) {
|
int32_t tempToX10Watts(int32_t rawTemp) {
|
||||||
// mass is in milliJ/*C, rawC is raw per degree C
|
// mass is in milliJ/*C, rawC is raw per degree C
|
||||||
@@ -30,31 +30,31 @@ void setTipX10Watts(int32_t mw) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t availableW10(uint8_t sample) {
|
static uint32_t availableW10(uint8_t sample) {
|
||||||
//P = V^2 / R, v*v = v^2 * 100
|
// P = V^2 / R, v*v = v^2 * 100
|
||||||
// R = R*10
|
// R = R*10
|
||||||
// P therefore is in V^2*100/R*10 = W*10.
|
// P therefore is in V^2*100/R*10 = W*10.
|
||||||
uint32_t v = getInputVoltageX10(systemSettings.voltageDiv, sample); // 100 = 10v
|
uint32_t v = getInputVoltageX10(systemSettings.voltageDiv, sample); // 100 = 10v
|
||||||
uint32_t availableWattsX10 = (v * v) / tipResistance;
|
uint32_t availableWattsX10 = (v * v) / tipResistance;
|
||||||
//However, 100% duty cycle is not possible as there is a dead time while the ADC takes a reading
|
// However, 100% duty cycle is not possible as there is a dead time while the ADC takes a reading
|
||||||
//Therefore need to scale available milliwats by this
|
// Therefore need to scale available milliwats by this
|
||||||
|
|
||||||
// avMw=(AvMw*powerPWM)/totalPWM.
|
// avMw=(AvMw*powerPWM)/totalPWM.
|
||||||
availableWattsX10 = availableWattsX10 * powerPWM;
|
availableWattsX10 = availableWattsX10 * powerPWM;
|
||||||
availableWattsX10 /= totalPWM;
|
availableWattsX10 /= totalPWM;
|
||||||
|
|
||||||
//availableMilliWattsX10 is now an accurate representation
|
// availableMilliWattsX10 is now an accurate representation
|
||||||
return availableWattsX10;
|
return availableWattsX10;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t X10WattsToPWM(int32_t milliWatts, uint8_t sample) {
|
uint8_t X10WattsToPWM(int32_t milliWatts, uint8_t sample) {
|
||||||
// Scale input milliWatts to the pwm range available
|
// Scale input milliWatts to the pwm range available
|
||||||
if (milliWatts < 1) {
|
if (milliWatts < 1) {
|
||||||
//keep the battery voltage updating the filter
|
// keep the battery voltage updating the filter
|
||||||
getInputVoltageX10(systemSettings.voltageDiv, sample);
|
getInputVoltageX10(systemSettings.voltageDiv, sample);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Calculate desired milliwatts as a percentage of availableW10
|
// Calculate desired milliwatts as a percentage of availableW10
|
||||||
uint32_t pwm;
|
uint32_t pwm;
|
||||||
do {
|
do {
|
||||||
pwm = (powerPWM * milliWatts) / availableW10(sample);
|
pwm = (powerPWM * milliWatts) / availableW10(sample);
|
||||||
@@ -69,7 +69,7 @@ uint8_t X10WattsToPWM(int32_t milliWatts, uint8_t sample) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int32_t PWMToX10Watts(uint8_t pwm, uint8_t sample) {
|
static int32_t PWMToX10Watts(uint8_t pwm, uint8_t sample) {
|
||||||
uint32_t maxMW = availableW10(sample); //Get the milliwatts for the max pwm period
|
uint32_t maxMW = availableW10(sample); // Get the milliwatts for the max pwm period
|
||||||
//Then convert pwm into percentage of powerPWM to get the percentage of the max mw
|
// Then convert pwm into percentage of powerPWM to get the percentage of the max mw
|
||||||
return (((uint32_t) pwm) * maxMW) / powerPWM;
|
return (((uint32_t)pwm) * maxMW) / powerPWM;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,14 @@
|
|||||||
/* Includes */
|
/* Includes */
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <time.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/times.h>
|
#include <sys/times.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
/* Functions */
|
/* Functions */
|
||||||
void initialise_monitor_handles() {
|
void initialise_monitor_handles() {}
|
||||||
}
|
|
||||||
|
|
||||||
int _getpid(void) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int _getpid(void) { return 1; }
|
||||||
|
|||||||
@@ -200,8 +200,7 @@ static void gui_solderingTempAdjust() {
|
|||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case BUTTON_B_LONG:
|
case BUTTON_B_LONG:
|
||||||
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration >
|
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) {
|
||||||
PRESS_ACCEL_INTERVAL_MAX) {
|
|
||||||
if (systemSettings.ReverseButtonTempChangeEnabled) {
|
if (systemSettings.ReverseButtonTempChangeEnabled) {
|
||||||
systemSettings.SolderingTemp += systemSettings.TempChangeLongStep;
|
systemSettings.SolderingTemp += systemSettings.TempChangeLongStep;
|
||||||
} else
|
} else
|
||||||
@@ -218,8 +217,7 @@ static void gui_solderingTempAdjust() {
|
|||||||
systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep;
|
systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep;
|
||||||
break;
|
break;
|
||||||
case BUTTON_F_LONG:
|
case BUTTON_F_LONG:
|
||||||
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration >
|
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) {
|
||||||
PRESS_ACCEL_INTERVAL_MAX) {
|
|
||||||
if (systemSettings.ReverseButtonTempChangeEnabled) {
|
if (systemSettings.ReverseButtonTempChangeEnabled) {
|
||||||
systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep;
|
systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep;
|
||||||
} else
|
} else
|
||||||
@@ -237,10 +235,8 @@ static void gui_solderingTempAdjust() {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) <
|
if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < PRESS_ACCEL_INTERVAL_MIN) {
|
||||||
PRESS_ACCEL_INTERVAL_MIN) {
|
autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN;
|
||||||
autoRepeatAcceleration =
|
|
||||||
PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN;
|
|
||||||
}
|
}
|
||||||
// constrain between 10-450 C
|
// constrain between 10-450 C
|
||||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||||
@@ -298,12 +294,12 @@ static void gui_solderingTempAdjust() {
|
|||||||
static bool shouldShutdown() {
|
static bool shouldShutdown() {
|
||||||
if (systemSettings.ShutdownTime) { // only allow shutdown exit if time > 0
|
if (systemSettings.ShutdownTime) { // only allow shutdown exit if time > 0
|
||||||
if (lastMovementTime) {
|
if (lastMovementTime) {
|
||||||
if (((TickType_t) (xTaskGetTickCount() - lastMovementTime)) > (TickType_t) (systemSettings.ShutdownTime * TICKS_MIN)) {
|
if (((TickType_t)(xTaskGetTickCount() - lastMovementTime)) > (TickType_t)(systemSettings.ShutdownTime * TICKS_MIN)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lastHallEffectSleepStart) {
|
if (lastHallEffectSleepStart) {
|
||||||
if (((TickType_t) (xTaskGetTickCount() - lastHallEffectSleepStart)) > (TickType_t) (systemSettings.ShutdownTime * TICKS_MIN)) {
|
if (((TickType_t)(xTaskGetTickCount() - lastHallEffectSleepStart)) > (TickType_t)(systemSettings.ShutdownTime * TICKS_MIN)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,7 +311,7 @@ static int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) {
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// user moved or pressed a button, go back to soldering
|
// user moved or pressed a button, go back to soldering
|
||||||
//If in the first two seconds we disable this to let accelerometer warm up
|
// If in the first two seconds we disable this to let accelerometer warm up
|
||||||
|
|
||||||
#ifdef POW_DC
|
#ifdef POW_DC
|
||||||
if (checkVoltageForExit())
|
if (checkVoltageForExit())
|
||||||
@@ -416,10 +412,10 @@ static uint32_t getSleepTimeout() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static bool shouldBeSleeping(bool inAutoStart) {
|
static bool shouldBeSleeping(bool inAutoStart) {
|
||||||
// Return true if the iron should be in sleep mode
|
// Return true if the iron should be in sleep mode
|
||||||
if (systemSettings.sensitivity && systemSettings.SleepTime) {
|
if (systemSettings.sensitivity && systemSettings.SleepTime) {
|
||||||
if (inAutoStart) {
|
if (inAutoStart) {
|
||||||
//In auto start we are asleep until movement
|
// In auto start we are asleep until movement
|
||||||
if (lastMovementTime == 0 && lastButtonTime == 0) {
|
if (lastMovementTime == 0 && lastButtonTime == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -531,8 +527,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
|
|||||||
if (oldTemp != systemSettings.SolderingTemp) {
|
if (oldTemp != systemSettings.SolderingTemp) {
|
||||||
saveSettings(); // only save on change
|
saveSettings(); // only save on change
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
case BUTTON_BOTH_LONG:
|
case BUTTON_BOTH_LONG:
|
||||||
if (systemSettings.lockingMode != 0) {
|
if (systemSettings.lockingMode != 0) {
|
||||||
// Lock buttons
|
// Lock buttons
|
||||||
@@ -705,13 +700,13 @@ void showDebugMenu(void) {
|
|||||||
if (getIsPoweredByDCIN()) {
|
if (getIsPoweredByDCIN()) {
|
||||||
OLED::printNumber(0, 1);
|
OLED::printNumber(0, 1);
|
||||||
} else {
|
} else {
|
||||||
//We are not powered via DC, so want to display the appropriate state for PD or QC
|
// We are not powered via DC, so want to display the appropriate state for PD or QC
|
||||||
bool poweredbyPD = false;
|
bool poweredbyPD = false;
|
||||||
#ifdef POW_PD
|
#ifdef POW_PD
|
||||||
if (usb_pd_detect()) {
|
if (usb_pd_detect()) {
|
||||||
//We are PD capable
|
// We are PD capable
|
||||||
if (PolicyEngine::pdHasNegotiated()) {
|
if (PolicyEngine::pdHasNegotiated()) {
|
||||||
//We are powered via PD
|
// We are powered via PD
|
||||||
poweredbyPD = true;
|
poweredbyPD = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -725,7 +720,7 @@ void showDebugMenu(void) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
//Max deg C limit
|
// Max deg C limit
|
||||||
OLED::printNumber(TipThermoModel::getTipMaxInC(), 3);
|
OLED::printNumber(TipThermoModel::getTipMaxInC(), 3);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -750,7 +745,7 @@ void showWarnings() {
|
|||||||
warnUser(SettingsResetMessage, 1, 10 * TICKS_SECOND);
|
warnUser(SettingsResetMessage, 1, 10 * TICKS_SECOND);
|
||||||
}
|
}
|
||||||
#ifndef NO_WARN_MISSING
|
#ifndef NO_WARN_MISSING
|
||||||
//We also want to alert if accel or pd is not detected / not responding
|
// We also want to alert if accel or pd is not detected / not responding
|
||||||
// In this case though, we dont want to nag the user _too_ much
|
// In this case though, we dont want to nag the user _too_ much
|
||||||
// So only show first 2 times
|
// So only show first 2 times
|
||||||
while (DetectedAccelerometerVersion == ACCELEROMETERS_SCANNING) {
|
while (DetectedAccelerometerVersion == ACCELEROMETERS_SCANNING) {
|
||||||
@@ -765,7 +760,7 @@ void showWarnings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef POW_PD
|
#ifdef POW_PD
|
||||||
//We expect pd to be present
|
// We expect pd to be present
|
||||||
if (!usb_pd_detect()) {
|
if (!usb_pd_detect()) {
|
||||||
if (systemSettings.pdMissingWarningCounter < 2) {
|
if (systemSettings.pdMissingWarningCounter < 2) {
|
||||||
systemSettings.pdMissingWarningCounter++;
|
systemSettings.pdMissingWarningCounter++;
|
||||||
@@ -871,8 +866,7 @@ void startGUITask(void const *argument __unused) {
|
|||||||
// This is zero cost really as state is only changed on display updates
|
// This is zero cost really as state is only changed on display updates
|
||||||
OLED::setDisplayState(OLED::DisplayState::ON);
|
OLED::setDisplayState(OLED::DisplayState::ON);
|
||||||
|
|
||||||
if ((tipTemp < 50) && systemSettings.sensitivity && (((xTaskGetTickCount() - lastMovementTime) >
|
if ((tipTemp < 50) && systemSettings.sensitivity && (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) {
|
||||||
MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) {
|
|
||||||
OLED::setDisplayState(OLED::DisplayState::OFF);
|
OLED::setDisplayState(OLED::DisplayState::OFF);
|
||||||
}
|
}
|
||||||
uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5;
|
uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5;
|
||||||
@@ -935,13 +929,13 @@ void startGUITask(void const *argument __unused) {
|
|||||||
OLED::fillArea(0, 0, 41, 16, 0); // clear the area
|
OLED::fillArea(0, 0, 41, 16, 0); // clear the area
|
||||||
OLED::setCursor(0, 0);
|
OLED::setCursor(0, 0);
|
||||||
}
|
}
|
||||||
//If we have a tip connected draw the temp, if not we leave it blank
|
// If we have a tip connected draw the temp, if not we leave it blank
|
||||||
if (!tipDisconnectedDisplay) {
|
if (!tipDisconnectedDisplay) {
|
||||||
// draw in the temp
|
// draw in the temp
|
||||||
if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 26 < 16)))
|
if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 26 < 16)))
|
||||||
gui_drawTipTemp(false); // draw in the temp
|
gui_drawTipTemp(false); // draw in the temp
|
||||||
} else {
|
} else {
|
||||||
//Draw in missing tip symbol
|
// Draw in missing tip symbol
|
||||||
|
|
||||||
#ifdef OLED_FLIP
|
#ifdef OLED_FLIP
|
||||||
if (!OLED::getRotation()) {
|
if (!OLED::getRotation()) {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "BMA223.hpp"
|
#include "BMA223.hpp"
|
||||||
#include "SC7A20.hpp"
|
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "I2C_Wrapper.hpp"
|
#include "I2C_Wrapper.hpp"
|
||||||
@@ -14,6 +13,7 @@
|
|||||||
#include "MMA8652FC.hpp"
|
#include "MMA8652FC.hpp"
|
||||||
#include "MSA301.h"
|
#include "MSA301.h"
|
||||||
#include "QC3.h"
|
#include "QC3.h"
|
||||||
|
#include "SC7A20.hpp"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "TipThermoModel.h"
|
#include "TipThermoModel.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
@@ -115,9 +115,9 @@ void startMOVTask(void const *argument __unused) {
|
|||||||
if (systemSettings.autoStartMode)
|
if (systemSettings.autoStartMode)
|
||||||
osDelay(2 * TICKS_SECOND);
|
osDelay(2 * TICKS_SECOND);
|
||||||
|
|
||||||
int16_t datax[MOVFilter] = { 0 };
|
int16_t datax[MOVFilter] = {0};
|
||||||
int16_t datay[MOVFilter] = { 0 };
|
int16_t datay[MOVFilter] = {0};
|
||||||
int16_t dataz[MOVFilter] = { 0 };
|
int16_t dataz[MOVFilter] = {0};
|
||||||
uint8_t currentPointer = 0;
|
uint8_t currentPointer = 0;
|
||||||
int16_t tx = 0, ty = 0, tz = 0;
|
int16_t tx = 0, ty = 0, tz = 0;
|
||||||
int32_t avgx, avgy, avgz;
|
int32_t avgx, avgy, avgz;
|
||||||
@@ -133,14 +133,14 @@ void startMOVTask(void const *argument __unused) {
|
|||||||
OLED::setRotation(rotation == ORIENTATION_LEFT_HAND); // link the data through
|
OLED::setRotation(rotation == ORIENTATION_LEFT_HAND); // link the data through
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
datax[currentPointer] = (int32_t) tx;
|
datax[currentPointer] = (int32_t)tx;
|
||||||
datay[currentPointer] = (int32_t) ty;
|
datay[currentPointer] = (int32_t)ty;
|
||||||
dataz[currentPointer] = (int32_t) tz;
|
dataz[currentPointer] = (int32_t)tz;
|
||||||
if (!accelInit) {
|
if (!accelInit) {
|
||||||
for (uint8_t i = currentPointer + 1; i < MOVFilter; i++) {
|
for (uint8_t i = currentPointer + 1; i < MOVFilter; i++) {
|
||||||
datax[i] = (int32_t) tx;
|
datax[i] = (int32_t)tx;
|
||||||
datay[i] = (int32_t) ty;
|
datay[i] = (int32_t)ty;
|
||||||
dataz[i] = (int32_t) tz;
|
dataz[i] = (int32_t)tz;
|
||||||
}
|
}
|
||||||
accelInit = 1;
|
accelInit = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,15 @@
|
|||||||
* Author: Ralim
|
* Author: Ralim
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.hpp"
|
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
#include "power.hpp"
|
#include "FreeRTOS.h"
|
||||||
#include "history.hpp"
|
#include "Settings.h"
|
||||||
#include "TipThermoModel.h"
|
#include "TipThermoModel.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "FreeRTOS.h"
|
#include "history.hpp"
|
||||||
|
#include "main.hpp"
|
||||||
|
#include "power.hpp"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "Settings.h"
|
|
||||||
static TickType_t powerPulseRate = 10000;
|
static TickType_t powerPulseRate = 10000;
|
||||||
static TickType_t powerPulseDuration = 250;
|
static TickType_t powerPulseDuration = 250;
|
||||||
TaskHandle_t pidTaskNotification = NULL;
|
TaskHandle_t pidTaskNotification = NULL;
|
||||||
@@ -29,7 +29,7 @@ void startPIDTask(void const *argument __unused) {
|
|||||||
TickType_t lastPowerPulseStart = 0;
|
TickType_t lastPowerPulseStart = 0;
|
||||||
TickType_t lastPowerPulseEnd = 0;
|
TickType_t lastPowerPulseEnd = 0;
|
||||||
|
|
||||||
history<int32_t, PID_TIM_HZ> tempError = { { 0 }, 0, 0 };
|
history<int32_t, PID_TIM_HZ> tempError = {{0}, 0, 0};
|
||||||
currentTempTargetDegC = 0; // Force start with no output (off). If in sleep / soldering this will
|
currentTempTargetDegC = 0; // Force start with no output (off). If in sleep / soldering this will
|
||||||
// be over-ridden rapidly
|
// be over-ridden rapidly
|
||||||
pidTaskNotification = xTaskGetCurrentTaskHandle();
|
pidTaskNotification = xTaskGetCurrentTaskHandle();
|
||||||
@@ -45,10 +45,10 @@ void startPIDTask(void const *argument __unused) {
|
|||||||
if (PIDTempTarget) {
|
if (PIDTempTarget) {
|
||||||
// Cap the max set point to 450C
|
// Cap the max set point to 450C
|
||||||
if (PIDTempTarget > (450)) {
|
if (PIDTempTarget > (450)) {
|
||||||
//Maximum allowed output
|
// Maximum allowed output
|
||||||
PIDTempTarget = (450);
|
PIDTempTarget = (450);
|
||||||
}
|
}
|
||||||
//Safety check that not aiming higher than current tip can measure
|
// Safety check that not aiming higher than current tip can measure
|
||||||
if (PIDTempTarget > TipThermoModel::getTipMaxInC()) {
|
if (PIDTempTarget > TipThermoModel::getTipMaxInC()) {
|
||||||
PIDTempTarget = TipThermoModel::getTipMaxInC();
|
PIDTempTarget = TipThermoModel::getTipMaxInC();
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ void startPIDTask(void const *argument __unused) {
|
|||||||
// Once we have feed-forward temp estimation we should be able to better tune this.
|
// Once we have feed-forward temp estimation we should be able to better tune this.
|
||||||
|
|
||||||
int32_t x10WattsNeeded = tempToX10Watts(tError);
|
int32_t x10WattsNeeded = tempToX10Watts(tError);
|
||||||
// tempError.average());
|
// tempError.average());
|
||||||
// note that milliWattsNeeded is sometimes negative, this counters overshoot
|
// note that milliWattsNeeded is sometimes negative, this counters overshoot
|
||||||
// from I term's inertia.
|
// from I term's inertia.
|
||||||
x10WattsOut += x10WattsNeeded;
|
x10WattsOut += x10WattsNeeded;
|
||||||
@@ -89,31 +89,26 @@ void startPIDTask(void const *argument __unused) {
|
|||||||
// and counters extra power if the iron is no longer losing temp.
|
// and counters extra power if the iron is no longer losing temp.
|
||||||
// basically: temp - lastTemp
|
// basically: temp - lastTemp
|
||||||
// Unfortunately, our temp signal is too noisy to really help.
|
// Unfortunately, our temp signal is too noisy to really help.
|
||||||
|
|
||||||
}
|
}
|
||||||
//If the user turns on the option of using an occasional pulse to keep the power bank on
|
// If the user turns on the option of using an occasional pulse to keep the power bank on
|
||||||
if (systemSettings.KeepAwakePulse) {
|
if (systemSettings.KeepAwakePulse) {
|
||||||
|
|
||||||
if (xTaskGetTickCount() - lastPowerPulseStart
|
if (xTaskGetTickCount() - lastPowerPulseStart > powerPulseRate) {
|
||||||
> powerPulseRate) {
|
|
||||||
lastPowerPulseStart = xTaskGetTickCount();
|
lastPowerPulseStart = xTaskGetTickCount();
|
||||||
lastPowerPulseEnd = lastPowerPulseStart
|
lastPowerPulseEnd = lastPowerPulseStart + powerPulseDuration;
|
||||||
+ powerPulseDuration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//If current PID is less than the pulse level, check if we want to constrain to the pulse as the floor
|
// If current PID is less than the pulse level, check if we want to constrain to the pulse as the floor
|
||||||
if (x10WattsOut < systemSettings.KeepAwakePulse
|
if (x10WattsOut < systemSettings.KeepAwakePulse && xTaskGetTickCount() < lastPowerPulseEnd) {
|
||||||
&& xTaskGetTickCount() < lastPowerPulseEnd) {
|
|
||||||
x10WattsOut = systemSettings.KeepAwakePulse;
|
x10WattsOut = systemSettings.KeepAwakePulse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Secondary safety check to forcefully disable header when within ADC noise of top of ADC
|
// Secondary safety check to forcefully disable header when within ADC noise of top of ADC
|
||||||
if (getTipRawTemp(0) > (0x7FFF - 150)) {
|
if (getTipRawTemp(0) > (0x7FFF - 150)) {
|
||||||
x10WattsOut = 0;
|
x10WattsOut = 0;
|
||||||
}
|
}
|
||||||
if (systemSettings.powerLimit
|
if (systemSettings.powerLimit && x10WattsOut > (systemSettings.powerLimit * 10)) {
|
||||||
&& x10WattsOut > (systemSettings.powerLimit * 10)) {
|
|
||||||
setTipX10Watts(systemSettings.powerLimit * 10);
|
setTipX10Watts(systemSettings.powerLimit * 10);
|
||||||
} else {
|
} else {
|
||||||
setTipX10Watts(x10WattsOut);
|
setTipX10Watts(x10WattsOut);
|
||||||
@@ -121,7 +116,7 @@ void startPIDTask(void const *argument __unused) {
|
|||||||
|
|
||||||
resetWatchdog();
|
resetWatchdog();
|
||||||
} else {
|
} else {
|
||||||
//ADC interrupt timeout
|
// ADC interrupt timeout
|
||||||
setTipPWM(0);
|
setTipPWM(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -25,29 +25,29 @@
|
|||||||
* 1 tab == 4 spaces!
|
* 1 tab == 4 spaces!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "croutine.h"
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "croutine.h"
|
|
||||||
|
|
||||||
/* Remove the whole file is co-routines are not being used. */
|
/* Remove the whole file is co-routines are not being used. */
|
||||||
#if( configUSE_CO_ROUTINES != 0 )
|
#if (configUSE_CO_ROUTINES != 0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Some kernel aware debuggers require data to be viewed to be global, rather
|
* Some kernel aware debuggers require data to be viewed to be global, rather
|
||||||
* than file scope.
|
* than file scope.
|
||||||
*/
|
*/
|
||||||
#ifdef portREMOVE_STATIC_QUALIFIER
|
#ifdef portREMOVE_STATIC_QUALIFIER
|
||||||
#define static
|
#define static
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Lists for ready and blocked co-routines. --------------------*/
|
/* Lists for ready and blocked co-routines. --------------------*/
|
||||||
static List_t pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /*< Prioritised ready co-routines. */
|
static List_t pxReadyCoRoutineLists[configMAX_CO_ROUTINE_PRIORITIES]; /*< Prioritised ready co-routines. */
|
||||||
static List_t xDelayedCoRoutineList1; /*< Delayed co-routines. */
|
static List_t xDelayedCoRoutineList1; /*< Delayed co-routines. */
|
||||||
static List_t xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */
|
static List_t xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */
|
||||||
static List_t * pxDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used. */
|
static List_t *pxDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used. */
|
||||||
static List_t * pxOverflowDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */
|
static List_t *pxOverflowDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */
|
||||||
static List_t xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */
|
static List_t xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by
|
||||||
|
interrupts. */
|
||||||
|
|
||||||
/* Other file private variables. --------------------------------*/
|
/* Other file private variables. --------------------------------*/
|
||||||
CRCB_t * pxCurrentCoRoutine = NULL;
|
CRCB_t * pxCurrentCoRoutine = NULL;
|
||||||
@@ -55,7 +55,7 @@ static UBaseType_t uxTopCoRoutineReadyPriority = 0;
|
|||||||
static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0;
|
static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0;
|
||||||
|
|
||||||
/* The initial state of the co-routine when it is created. */
|
/* The initial state of the co-routine when it is created. */
|
||||||
#define corINITIAL_STATE ( 0 )
|
#define corINITIAL_STATE (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Place the co-routine represented by pxCRCB into the appropriate ready queue
|
* Place the co-routine represented by pxCRCB into the appropriate ready queue
|
||||||
@@ -64,20 +64,19 @@ static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0;
|
|||||||
* This macro accesses the co-routine ready lists and therefore must not be
|
* This macro accesses the co-routine ready lists and therefore must not be
|
||||||
* used from within an ISR.
|
* used from within an ISR.
|
||||||
*/
|
*/
|
||||||
#define prvAddCoRoutineToReadyQueue( pxCRCB ) \
|
#define prvAddCoRoutineToReadyQueue(pxCRCB) \
|
||||||
{ \
|
|
||||||
if( pxCRCB->uxPriority > uxTopCoRoutineReadyPriority ) \
|
|
||||||
{ \
|
{ \
|
||||||
|
if (pxCRCB->uxPriority > uxTopCoRoutineReadyPriority) { \
|
||||||
uxTopCoRoutineReadyPriority = pxCRCB->uxPriority; \
|
uxTopCoRoutineReadyPriority = pxCRCB->uxPriority; \
|
||||||
} \
|
} \
|
||||||
vListInsertEnd( ( List_t * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) ); \
|
vListInsertEnd((List_t *)&(pxReadyCoRoutineLists[pxCRCB->uxPriority]), &(pxCRCB->xGenericListItem)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Utility to ready all the lists used by the scheduler. This is called
|
* Utility to ready all the lists used by the scheduler. This is called
|
||||||
* automatically upon the creation of the first co-routine.
|
* automatically upon the creation of the first co-routine.
|
||||||
*/
|
*/
|
||||||
static void prvInitialiseCoRoutineLists( void );
|
static void prvInitialiseCoRoutineLists(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Co-routines that are readied by an interrupt cannot be placed directly into
|
* Co-routines that are readied by an interrupt cannot be placed directly into
|
||||||
@@ -85,7 +84,7 @@ static void prvInitialiseCoRoutineLists( void );
|
|||||||
* in the pending ready list in order that they can later be moved to the ready
|
* in the pending ready list in order that they can later be moved to the ready
|
||||||
* list by the co-routine scheduler.
|
* list by the co-routine scheduler.
|
||||||
*/
|
*/
|
||||||
static void prvCheckPendingReadyList( void );
|
static void prvCheckPendingReadyList(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Macro that looks at the list of co-routines that are currently delayed to
|
* Macro that looks at the list of co-routines that are currently delayed to
|
||||||
@@ -95,30 +94,26 @@ static void prvCheckPendingReadyList( void );
|
|||||||
* meaning once one co-routine has been found whose timer has not expired
|
* meaning once one co-routine has been found whose timer has not expired
|
||||||
* we need not look any further down the list.
|
* we need not look any further down the list.
|
||||||
*/
|
*/
|
||||||
static void prvCheckDelayedList( void );
|
static void prvCheckDelayedList(void);
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex )
|
BaseType_t xCoRoutineCreate(crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex) {
|
||||||
{
|
BaseType_t xReturn;
|
||||||
BaseType_t xReturn;
|
CRCB_t * pxCoRoutine;
|
||||||
CRCB_t *pxCoRoutine;
|
|
||||||
|
|
||||||
/* Allocate the memory that will store the co-routine control block. */
|
/* Allocate the memory that will store the co-routine control block. */
|
||||||
pxCoRoutine = ( CRCB_t * ) pvPortMalloc( sizeof( CRCB_t ) );
|
pxCoRoutine = (CRCB_t *)pvPortMalloc(sizeof(CRCB_t));
|
||||||
if( pxCoRoutine )
|
if (pxCoRoutine) {
|
||||||
{
|
|
||||||
/* If pxCurrentCoRoutine is NULL then this is the first co-routine to
|
/* If pxCurrentCoRoutine is NULL then this is the first co-routine to
|
||||||
be created and the co-routine data structures need initialising. */
|
be created and the co-routine data structures need initialising. */
|
||||||
if( pxCurrentCoRoutine == NULL )
|
if (pxCurrentCoRoutine == NULL) {
|
||||||
{
|
|
||||||
pxCurrentCoRoutine = pxCoRoutine;
|
pxCurrentCoRoutine = pxCoRoutine;
|
||||||
prvInitialiseCoRoutineLists();
|
prvInitialiseCoRoutineLists();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check the priority is within limits. */
|
/* Check the priority is within limits. */
|
||||||
if( uxPriority >= configMAX_CO_ROUTINE_PRIORITIES )
|
if (uxPriority >= configMAX_CO_ROUTINE_PRIORITIES) {
|
||||||
{
|
|
||||||
uxPriority = configMAX_CO_ROUTINE_PRIORITIES - 1;
|
uxPriority = configMAX_CO_ROUTINE_PRIORITIES - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,26 +124,24 @@ CRCB_t *pxCoRoutine;
|
|||||||
pxCoRoutine->pxCoRoutineFunction = pxCoRoutineCode;
|
pxCoRoutine->pxCoRoutineFunction = pxCoRoutineCode;
|
||||||
|
|
||||||
/* Initialise all the other co-routine control block parameters. */
|
/* Initialise all the other co-routine control block parameters. */
|
||||||
vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) );
|
vListInitialiseItem(&(pxCoRoutine->xGenericListItem));
|
||||||
vListInitialiseItem( &( pxCoRoutine->xEventListItem ) );
|
vListInitialiseItem(&(pxCoRoutine->xEventListItem));
|
||||||
|
|
||||||
/* Set the co-routine control block as a link back from the ListItem_t.
|
/* Set the co-routine control block as a link back from the ListItem_t.
|
||||||
This is so we can get back to the containing CRCB from a generic item
|
This is so we can get back to the containing CRCB from a generic item
|
||||||
in a list. */
|
in a list. */
|
||||||
listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine );
|
listSET_LIST_ITEM_OWNER(&(pxCoRoutine->xGenericListItem), pxCoRoutine);
|
||||||
listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine );
|
listSET_LIST_ITEM_OWNER(&(pxCoRoutine->xEventListItem), pxCoRoutine);
|
||||||
|
|
||||||
/* Event lists are always in priority order. */
|
/* Event lists are always in priority order. */
|
||||||
listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), ( ( TickType_t ) configMAX_CO_ROUTINE_PRIORITIES - ( TickType_t ) uxPriority ) );
|
listSET_LIST_ITEM_VALUE(&(pxCoRoutine->xEventListItem), ((TickType_t)configMAX_CO_ROUTINE_PRIORITIES - (TickType_t)uxPriority));
|
||||||
|
|
||||||
/* Now the co-routine has been initialised it can be added to the ready
|
/* Now the co-routine has been initialised it can be added to the ready
|
||||||
list at the correct priority. */
|
list at the correct priority. */
|
||||||
prvAddCoRoutineToReadyQueue( pxCoRoutine );
|
prvAddCoRoutineToReadyQueue(pxCoRoutine);
|
||||||
|
|
||||||
xReturn = pdPASS;
|
xReturn = pdPASS;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;
|
xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,9 +149,8 @@ CRCB_t *pxCoRoutine;
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, List_t *pxEventList )
|
void vCoRoutineAddToDelayedList(TickType_t xTicksToDelay, List_t *pxEventList) {
|
||||||
{
|
TickType_t xTimeToWake;
|
||||||
TickType_t xTimeToWake;
|
|
||||||
|
|
||||||
/* Calculate the time to wake - this may overflow but this is
|
/* Calculate the time to wake - this may overflow but this is
|
||||||
not a problem. */
|
not a problem. */
|
||||||
@@ -167,70 +159,61 @@ TickType_t xTimeToWake;
|
|||||||
/* We must remove ourselves from the ready list before adding
|
/* We must remove ourselves from the ready list before adding
|
||||||
ourselves to the blocked list as the same list item is used for
|
ourselves to the blocked list as the same list item is used for
|
||||||
both lists. */
|
both lists. */
|
||||||
( void ) uxListRemove( ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) );
|
(void)uxListRemove((ListItem_t *)&(pxCurrentCoRoutine->xGenericListItem));
|
||||||
|
|
||||||
/* The list item will be inserted in wake time order. */
|
/* The list item will be inserted in wake time order. */
|
||||||
listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake );
|
listSET_LIST_ITEM_VALUE(&(pxCurrentCoRoutine->xGenericListItem), xTimeToWake);
|
||||||
|
|
||||||
if( xTimeToWake < xCoRoutineTickCount )
|
if (xTimeToWake < xCoRoutineTickCount) {
|
||||||
{
|
|
||||||
/* Wake time has overflowed. Place this item in the
|
/* Wake time has overflowed. Place this item in the
|
||||||
overflow list. */
|
overflow list. */
|
||||||
vListInsert( ( List_t * ) pxOverflowDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) );
|
vListInsert((List_t *)pxOverflowDelayedCoRoutineList, (ListItem_t *)&(pxCurrentCoRoutine->xGenericListItem));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* The wake time has not overflowed, so we can use the
|
/* The wake time has not overflowed, so we can use the
|
||||||
current block list. */
|
current block list. */
|
||||||
vListInsert( ( List_t * ) pxDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) );
|
vListInsert((List_t *)pxDelayedCoRoutineList, (ListItem_t *)&(pxCurrentCoRoutine->xGenericListItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
if( pxEventList )
|
if (pxEventList) {
|
||||||
{
|
|
||||||
/* Also add the co-routine to an event list. If this is done then the
|
/* Also add the co-routine to an event list. If this is done then the
|
||||||
function must be called with interrupts disabled. */
|
function must be called with interrupts disabled. */
|
||||||
vListInsert( pxEventList, &( pxCurrentCoRoutine->xEventListItem ) );
|
vListInsert(pxEventList, &(pxCurrentCoRoutine->xEventListItem));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static void prvCheckPendingReadyList( void )
|
static void prvCheckPendingReadyList(void) {
|
||||||
{
|
|
||||||
/* Are there any co-routines waiting to get moved to the ready list? These
|
/* Are there any co-routines waiting to get moved to the ready list? These
|
||||||
are co-routines that have been readied by an ISR. The ISR cannot access
|
are co-routines that have been readied by an ISR. The ISR cannot access
|
||||||
the ready lists itself. */
|
the ready lists itself. */
|
||||||
while( listLIST_IS_EMPTY( &xPendingReadyCoRoutineList ) == pdFALSE )
|
while (listLIST_IS_EMPTY(&xPendingReadyCoRoutineList) == pdFALSE) {
|
||||||
{
|
|
||||||
CRCB_t *pxUnblockedCRCB;
|
CRCB_t *pxUnblockedCRCB;
|
||||||
|
|
||||||
/* The pending ready list can be accessed by an ISR. */
|
/* The pending ready list can be accessed by an ISR. */
|
||||||
portDISABLE_INTERRUPTS();
|
portDISABLE_INTERRUPTS();
|
||||||
{
|
{
|
||||||
pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) );
|
pxUnblockedCRCB = (CRCB_t *)listGET_OWNER_OF_HEAD_ENTRY((&xPendingReadyCoRoutineList));
|
||||||
( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );
|
(void)uxListRemove(&(pxUnblockedCRCB->xEventListItem));
|
||||||
}
|
}
|
||||||
portENABLE_INTERRUPTS();
|
portENABLE_INTERRUPTS();
|
||||||
|
|
||||||
( void ) uxListRemove( &( pxUnblockedCRCB->xGenericListItem ) );
|
(void)uxListRemove(&(pxUnblockedCRCB->xGenericListItem));
|
||||||
prvAddCoRoutineToReadyQueue( pxUnblockedCRCB );
|
prvAddCoRoutineToReadyQueue(pxUnblockedCRCB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static void prvCheckDelayedList( void )
|
static void prvCheckDelayedList(void) {
|
||||||
{
|
CRCB_t *pxCRCB;
|
||||||
CRCB_t *pxCRCB;
|
|
||||||
|
|
||||||
xPassedTicks = xTaskGetTickCount() - xLastTickCount;
|
xPassedTicks = xTaskGetTickCount() - xLastTickCount;
|
||||||
while( xPassedTicks )
|
while (xPassedTicks) {
|
||||||
{
|
|
||||||
xCoRoutineTickCount++;
|
xCoRoutineTickCount++;
|
||||||
xPassedTicks--;
|
xPassedTicks--;
|
||||||
|
|
||||||
/* If the tick count has overflowed we need to swap the ready lists. */
|
/* If the tick count has overflowed we need to swap the ready lists. */
|
||||||
if( xCoRoutineTickCount == 0 )
|
if (xCoRoutineTickCount == 0) {
|
||||||
{
|
List_t *pxTemp;
|
||||||
List_t * pxTemp;
|
|
||||||
|
|
||||||
/* Tick count has overflowed so we need to swap the delay lists. If there are
|
/* Tick count has overflowed so we need to swap the delay lists. If there are
|
||||||
any items in pxDelayedCoRoutineList here then there is an error! */
|
any items in pxDelayedCoRoutineList here then there is an error! */
|
||||||
@@ -240,12 +223,10 @@ CRCB_t *pxCRCB;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* See if this tick has made a timeout expire. */
|
/* See if this tick has made a timeout expire. */
|
||||||
while( listLIST_IS_EMPTY( pxDelayedCoRoutineList ) == pdFALSE )
|
while (listLIST_IS_EMPTY(pxDelayedCoRoutineList) == pdFALSE) {
|
||||||
{
|
pxCRCB = (CRCB_t *)listGET_OWNER_OF_HEAD_ENTRY(pxDelayedCoRoutineList);
|
||||||
pxCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList );
|
|
||||||
|
|
||||||
if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) )
|
if (xCoRoutineTickCount < listGET_LIST_ITEM_VALUE(&(pxCRCB->xGenericListItem))) {
|
||||||
{
|
|
||||||
/* Timeout not yet expired. */
|
/* Timeout not yet expired. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -257,17 +238,16 @@ CRCB_t *pxCRCB;
|
|||||||
have been moved to the pending ready list and the following
|
have been moved to the pending ready list and the following
|
||||||
line is still valid. Also the pvContainer parameter will have
|
line is still valid. Also the pvContainer parameter will have
|
||||||
been set to NULL so the following lines are also valid. */
|
been set to NULL so the following lines are also valid. */
|
||||||
( void ) uxListRemove( &( pxCRCB->xGenericListItem ) );
|
(void)uxListRemove(&(pxCRCB->xGenericListItem));
|
||||||
|
|
||||||
/* Is the co-routine waiting on an event also? */
|
/* Is the co-routine waiting on an event also? */
|
||||||
if( pxCRCB->xEventListItem.pxContainer )
|
if (pxCRCB->xEventListItem.pxContainer) {
|
||||||
{
|
(void)uxListRemove(&(pxCRCB->xEventListItem));
|
||||||
( void ) uxListRemove( &( pxCRCB->xEventListItem ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
portENABLE_INTERRUPTS();
|
portENABLE_INTERRUPTS();
|
||||||
|
|
||||||
prvAddCoRoutineToReadyQueue( pxCRCB );
|
prvAddCoRoutineToReadyQueue(pxCRCB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,8 +255,7 @@ CRCB_t *pxCRCB;
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vCoRoutineSchedule( void )
|
void vCoRoutineSchedule(void) {
|
||||||
{
|
|
||||||
/* See if any co-routines readied by events need moving to the ready lists. */
|
/* See if any co-routines readied by events need moving to the ready lists. */
|
||||||
prvCheckPendingReadyList();
|
prvCheckPendingReadyList();
|
||||||
|
|
||||||
@@ -284,10 +263,8 @@ void vCoRoutineSchedule( void )
|
|||||||
prvCheckDelayedList();
|
prvCheckDelayedList();
|
||||||
|
|
||||||
/* Find the highest priority queue that contains ready co-routines. */
|
/* Find the highest priority queue that contains ready co-routines. */
|
||||||
while( listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) )
|
while (listLIST_IS_EMPTY(&(pxReadyCoRoutineLists[uxTopCoRoutineReadyPriority]))) {
|
||||||
{
|
if (uxTopCoRoutineReadyPriority == 0) {
|
||||||
if( uxTopCoRoutineReadyPriority == 0 )
|
|
||||||
{
|
|
||||||
/* No more co-routines to check. */
|
/* No more co-routines to check. */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -296,27 +273,25 @@ void vCoRoutineSchedule( void )
|
|||||||
|
|
||||||
/* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the co-routines
|
/* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the co-routines
|
||||||
of the same priority get an equal share of the processor time. */
|
of the same priority get an equal share of the processor time. */
|
||||||
listGET_OWNER_OF_NEXT_ENTRY( pxCurrentCoRoutine, &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) );
|
listGET_OWNER_OF_NEXT_ENTRY(pxCurrentCoRoutine, &(pxReadyCoRoutineLists[uxTopCoRoutineReadyPriority]));
|
||||||
|
|
||||||
/* Call the co-routine. */
|
/* Call the co-routine. */
|
||||||
( pxCurrentCoRoutine->pxCoRoutineFunction )( pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex );
|
(pxCurrentCoRoutine->pxCoRoutineFunction)(pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static void prvInitialiseCoRoutineLists( void )
|
static void prvInitialiseCoRoutineLists(void) {
|
||||||
{
|
UBaseType_t uxPriority;
|
||||||
UBaseType_t uxPriority;
|
|
||||||
|
|
||||||
for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ )
|
for (uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++) {
|
||||||
{
|
vListInitialise((List_t *)&(pxReadyCoRoutineLists[uxPriority]));
|
||||||
vListInitialise( ( List_t * ) &( pxReadyCoRoutineLists[ uxPriority ] ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vListInitialise( ( List_t * ) &xDelayedCoRoutineList1 );
|
vListInitialise((List_t *)&xDelayedCoRoutineList1);
|
||||||
vListInitialise( ( List_t * ) &xDelayedCoRoutineList2 );
|
vListInitialise((List_t *)&xDelayedCoRoutineList2);
|
||||||
vListInitialise( ( List_t * ) &xPendingReadyCoRoutineList );
|
vListInitialise((List_t *)&xPendingReadyCoRoutineList);
|
||||||
|
|
||||||
/* Start with pxDelayedCoRoutineList using list1 and the
|
/* Start with pxDelayedCoRoutineList using list1 and the
|
||||||
pxOverflowDelayedCoRoutineList using list2. */
|
pxOverflowDelayedCoRoutineList using list2. */
|
||||||
@@ -325,24 +300,20 @@ UBaseType_t uxPriority;
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
BaseType_t xCoRoutineRemoveFromEventList( const List_t *pxEventList )
|
BaseType_t xCoRoutineRemoveFromEventList(const List_t *pxEventList) {
|
||||||
{
|
CRCB_t * pxUnblockedCRCB;
|
||||||
CRCB_t *pxUnblockedCRCB;
|
BaseType_t xReturn;
|
||||||
BaseType_t xReturn;
|
|
||||||
|
|
||||||
/* This function is called from within an interrupt. It can only access
|
/* This function is called from within an interrupt. It can only access
|
||||||
event lists and the pending ready list. This function assumes that a
|
event lists and the pending ready list. This function assumes that a
|
||||||
check has already been made to ensure pxEventList is not empty. */
|
check has already been made to ensure pxEventList is not empty. */
|
||||||
pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );
|
pxUnblockedCRCB = (CRCB_t *)listGET_OWNER_OF_HEAD_ENTRY(pxEventList);
|
||||||
( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );
|
(void)uxListRemove(&(pxUnblockedCRCB->xEventListItem));
|
||||||
vListInsertEnd( ( List_t * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) );
|
vListInsertEnd((List_t *)&(xPendingReadyCoRoutineList), &(pxUnblockedCRCB->xEventListItem));
|
||||||
|
|
||||||
if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority )
|
if (pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority) {
|
||||||
{
|
|
||||||
xReturn = pdTRUE;
|
xReturn = pdTRUE;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
xReturn = pdFALSE;
|
xReturn = pdFALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,4 +321,3 @@ BaseType_t xReturn;
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* configUSE_CO_ROUTINES == 0 */
|
#endif /* configUSE_CO_ROUTINES == 0 */
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ task.h is included from an application file. */
|
|||||||
|
|
||||||
/* FreeRTOS includes. */
|
/* FreeRTOS includes. */
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
|
#include "event_groups.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "timers.h"
|
#include "timers.h"
|
||||||
#include "event_groups.h"
|
|
||||||
|
|
||||||
/* Lint e961, e750 and e9021 are suppressed as a MISRA exception justified
|
/* Lint e961, e750 and e9021 are suppressed as a MISRA exception justified
|
||||||
because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
|
because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
|
||||||
@@ -49,29 +49,28 @@ correct privileged Vs unprivileged linkage and placement. */
|
|||||||
item value. It is important they don't clash with the
|
item value. It is important they don't clash with the
|
||||||
taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */
|
taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */
|
||||||
#if configUSE_16_BIT_TICKS == 1
|
#if configUSE_16_BIT_TICKS == 1
|
||||||
#define eventCLEAR_EVENTS_ON_EXIT_BIT 0x0100U
|
#define eventCLEAR_EVENTS_ON_EXIT_BIT 0x0100U
|
||||||
#define eventUNBLOCKED_DUE_TO_BIT_SET 0x0200U
|
#define eventUNBLOCKED_DUE_TO_BIT_SET 0x0200U
|
||||||
#define eventWAIT_FOR_ALL_BITS 0x0400U
|
#define eventWAIT_FOR_ALL_BITS 0x0400U
|
||||||
#define eventEVENT_BITS_CONTROL_BYTES 0xff00U
|
#define eventEVENT_BITS_CONTROL_BYTES 0xff00U
|
||||||
#else
|
#else
|
||||||
#define eventCLEAR_EVENTS_ON_EXIT_BIT 0x01000000UL
|
#define eventCLEAR_EVENTS_ON_EXIT_BIT 0x01000000UL
|
||||||
#define eventUNBLOCKED_DUE_TO_BIT_SET 0x02000000UL
|
#define eventUNBLOCKED_DUE_TO_BIT_SET 0x02000000UL
|
||||||
#define eventWAIT_FOR_ALL_BITS 0x04000000UL
|
#define eventWAIT_FOR_ALL_BITS 0x04000000UL
|
||||||
#define eventEVENT_BITS_CONTROL_BYTES 0xff000000UL
|
#define eventEVENT_BITS_CONTROL_BYTES 0xff000000UL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct EventGroupDef_t
|
typedef struct EventGroupDef_t {
|
||||||
{
|
|
||||||
EventBits_t uxEventBits;
|
EventBits_t uxEventBits;
|
||||||
List_t xTasksWaitingForBits; /*< List of tasks waiting for a bit to be set. */
|
List_t xTasksWaitingForBits; /*< List of tasks waiting for a bit to be set. */
|
||||||
|
|
||||||
#if( configUSE_TRACE_FACILITY == 1 )
|
#if (configUSE_TRACE_FACILITY == 1)
|
||||||
UBaseType_t uxEventGroupNumber;
|
UBaseType_t uxEventGroupNumber;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
|
#if ((configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1))
|
||||||
uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the event group is statically allocated to ensure no attempt is made to free the memory. */
|
uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the event group is statically allocated to ensure no attempt is made to free the memory. */
|
||||||
#endif
|
#endif
|
||||||
} EventGroup_t;
|
} EventGroup_t;
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
@@ -84,50 +83,47 @@ typedef struct EventGroupDef_t
|
|||||||
* wait condition is met if any of the bits set in uxBitsToWait for are also set
|
* wait condition is met if any of the bits set in uxBitsToWait for are also set
|
||||||
* in uxCurrentEventBits.
|
* in uxCurrentEventBits.
|
||||||
*/
|
*/
|
||||||
static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits ) PRIVILEGED_FUNCTION;
|
static BaseType_t prvTestWaitCondition(const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits) PRIVILEGED_FUNCTION;
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
#if (configSUPPORT_STATIC_ALLOCATION == 1)
|
||||||
|
|
||||||
EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t *pxEventGroupBuffer )
|
EventGroupHandle_t xEventGroupCreateStatic(StaticEventGroup_t *pxEventGroupBuffer) {
|
||||||
{
|
|
||||||
EventGroup_t *pxEventBits;
|
EventGroup_t *pxEventBits;
|
||||||
|
|
||||||
/* A StaticEventGroup_t object must be provided. */
|
/* A StaticEventGroup_t object must be provided. */
|
||||||
configASSERT( pxEventGroupBuffer );
|
configASSERT(pxEventGroupBuffer);
|
||||||
|
|
||||||
#if( configASSERT_DEFINED == 1 )
|
#if (configASSERT_DEFINED == 1)
|
||||||
{
|
{
|
||||||
/* Sanity check that the size of the structure used to declare a
|
/* Sanity check that the size of the structure used to declare a
|
||||||
variable of type StaticEventGroup_t equals the size of the real
|
variable of type StaticEventGroup_t equals the size of the real
|
||||||
event group structure. */
|
event group structure. */
|
||||||
volatile size_t xSize = sizeof( StaticEventGroup_t );
|
volatile size_t xSize = sizeof(StaticEventGroup_t);
|
||||||
configASSERT( xSize == sizeof( EventGroup_t ) );
|
configASSERT(xSize == sizeof(EventGroup_t));
|
||||||
} /*lint !e529 xSize is referenced if configASSERT() is defined. */
|
} /*lint !e529 xSize is referenced if configASSERT() is defined. */
|
||||||
#endif /* configASSERT_DEFINED */
|
#endif /* configASSERT_DEFINED */
|
||||||
|
|
||||||
/* The user has provided a statically allocated event group - use it. */
|
/* The user has provided a statically allocated event group - use it. */
|
||||||
pxEventBits = ( EventGroup_t * ) pxEventGroupBuffer; /*lint !e740 !e9087 EventGroup_t and StaticEventGroup_t are deliberately aliased for data hiding purposes and guaranteed to have the same size and alignment requirement - checked by configASSERT(). */
|
pxEventBits = (EventGroup_t *)pxEventGroupBuffer; /*lint !e740 !e9087 EventGroup_t and StaticEventGroup_t are deliberately aliased for data hiding purposes and guaranteed to have the same size and
|
||||||
|
alignment requirement - checked by configASSERT(). */
|
||||||
|
|
||||||
if( pxEventBits != NULL )
|
if (pxEventBits != NULL) {
|
||||||
{
|
|
||||||
pxEventBits->uxEventBits = 0;
|
pxEventBits->uxEventBits = 0;
|
||||||
vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
|
vListInitialise(&(pxEventBits->xTasksWaitingForBits));
|
||||||
|
|
||||||
#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
|
#if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
|
||||||
{
|
{
|
||||||
/* Both static and dynamic allocation can be used, so note that
|
/* Both static and dynamic allocation can be used, so note that
|
||||||
this event group was created statically in case the event group
|
this event group was created statically in case the event group
|
||||||
is later deleted. */
|
is later deleted. */
|
||||||
pxEventBits->ucStaticallyAllocated = pdTRUE;
|
pxEventBits->ucStaticallyAllocated = pdTRUE;
|
||||||
}
|
}
|
||||||
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
|
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
|
||||||
|
|
||||||
traceEVENT_GROUP_CREATE( pxEventBits );
|
traceEVENT_GROUP_CREATE(pxEventBits);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* xEventGroupCreateStatic should only ever be called with
|
/* xEventGroupCreateStatic should only ever be called with
|
||||||
pxEventGroupBuffer pointing to a pre-allocated (compile time
|
pxEventGroupBuffer pointing to a pre-allocated (compile time
|
||||||
allocated) StaticEventGroup_t variable. */
|
allocated) StaticEventGroup_t variable. */
|
||||||
@@ -135,15 +131,14 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, co
|
|||||||
}
|
}
|
||||||
|
|
||||||
return pxEventBits;
|
return pxEventBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
|
#if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
|
||||||
|
|
||||||
EventGroupHandle_t xEventGroupCreate( void )
|
EventGroupHandle_t xEventGroupCreate(void) {
|
||||||
{
|
|
||||||
EventGroup_t *pxEventBits;
|
EventGroup_t *pxEventBits;
|
||||||
|
|
||||||
/* Allocate the event group. Justification for MISRA deviation as
|
/* Allocate the event group. Justification for MISRA deviation as
|
||||||
@@ -159,86 +154,74 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, co
|
|||||||
sizeof( TickType_t ), the TickType_t variables will be accessed in two
|
sizeof( TickType_t ), the TickType_t variables will be accessed in two
|
||||||
or more reads operations, and the alignment requirements is only that
|
or more reads operations, and the alignment requirements is only that
|
||||||
of each individual read. */
|
of each individual read. */
|
||||||
pxEventBits = ( EventGroup_t * ) pvPortMalloc( sizeof( EventGroup_t ) ); /*lint !e9087 !e9079 see comment above. */
|
pxEventBits = (EventGroup_t *)pvPortMalloc(sizeof(EventGroup_t)); /*lint !e9087 !e9079 see comment above. */
|
||||||
|
|
||||||
if( pxEventBits != NULL )
|
if (pxEventBits != NULL) {
|
||||||
{
|
|
||||||
pxEventBits->uxEventBits = 0;
|
pxEventBits->uxEventBits = 0;
|
||||||
vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
|
vListInitialise(&(pxEventBits->xTasksWaitingForBits));
|
||||||
|
|
||||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
#if (configSUPPORT_STATIC_ALLOCATION == 1)
|
||||||
{
|
{
|
||||||
/* Both static and dynamic allocation can be used, so note this
|
/* Both static and dynamic allocation can be used, so note this
|
||||||
event group was allocated statically in case the event group is
|
event group was allocated statically in case the event group is
|
||||||
later deleted. */
|
later deleted. */
|
||||||
pxEventBits->ucStaticallyAllocated = pdFALSE;
|
pxEventBits->ucStaticallyAllocated = pdFALSE;
|
||||||
}
|
}
|
||||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||||
|
|
||||||
traceEVENT_GROUP_CREATE( pxEventBits );
|
traceEVENT_GROUP_CREATE(pxEventBits);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
traceEVENT_GROUP_CREATE_FAILED(); /*lint !e9063 Else branch only exists to allow tracing and does not generate code if trace macros are not defined. */
|
traceEVENT_GROUP_CREATE_FAILED(); /*lint !e9063 Else branch only exists to allow tracing and does not generate code if trace macros are not defined. */
|
||||||
}
|
}
|
||||||
|
|
||||||
return pxEventBits;
|
return pxEventBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
|
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait )
|
EventBits_t xEventGroupSync(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait) {
|
||||||
{
|
EventBits_t uxOriginalBitValue, uxReturn;
|
||||||
EventBits_t uxOriginalBitValue, uxReturn;
|
EventGroup_t *pxEventBits = xEventGroup;
|
||||||
EventGroup_t *pxEventBits = xEventGroup;
|
BaseType_t xAlreadyYielded;
|
||||||
BaseType_t xAlreadyYielded;
|
BaseType_t xTimeoutOccurred = pdFALSE;
|
||||||
BaseType_t xTimeoutOccurred = pdFALSE;
|
|
||||||
|
|
||||||
configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
|
configASSERT((uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES) == 0);
|
||||||
configASSERT( uxBitsToWaitFor != 0 );
|
configASSERT(uxBitsToWaitFor != 0);
|
||||||
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
|
#if ((INCLUDE_xTaskGetSchedulerState == 1) || (configUSE_TIMERS == 1))
|
||||||
{
|
{ configASSERT(!((xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED) && (xTicksToWait != 0))); }
|
||||||
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
|
#endif
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
vTaskSuspendAll();
|
vTaskSuspendAll();
|
||||||
{
|
{
|
||||||
uxOriginalBitValue = pxEventBits->uxEventBits;
|
uxOriginalBitValue = pxEventBits->uxEventBits;
|
||||||
|
|
||||||
( void ) xEventGroupSetBits( xEventGroup, uxBitsToSet );
|
(void)xEventGroupSetBits(xEventGroup, uxBitsToSet);
|
||||||
|
|
||||||
if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor )
|
if (((uxOriginalBitValue | uxBitsToSet) & uxBitsToWaitFor) == uxBitsToWaitFor) {
|
||||||
{
|
|
||||||
/* All the rendezvous bits are now set - no need to block. */
|
/* All the rendezvous bits are now set - no need to block. */
|
||||||
uxReturn = ( uxOriginalBitValue | uxBitsToSet );
|
uxReturn = (uxOriginalBitValue | uxBitsToSet);
|
||||||
|
|
||||||
/* Rendezvous always clear the bits. They will have been cleared
|
/* Rendezvous always clear the bits. They will have been cleared
|
||||||
already unless this is the only task in the rendezvous. */
|
already unless this is the only task in the rendezvous. */
|
||||||
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
||||||
|
|
||||||
xTicksToWait = 0;
|
xTicksToWait = 0;
|
||||||
}
|
} else {
|
||||||
else
|
if (xTicksToWait != (TickType_t)0) {
|
||||||
{
|
traceEVENT_GROUP_SYNC_BLOCK(xEventGroup, uxBitsToSet, uxBitsToWaitFor);
|
||||||
if( xTicksToWait != ( TickType_t ) 0 )
|
|
||||||
{
|
|
||||||
traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor );
|
|
||||||
|
|
||||||
/* Store the bits that the calling task is waiting for in the
|
/* Store the bits that the calling task is waiting for in the
|
||||||
task's event list item so the kernel knows when a match is
|
task's event list item so the kernel knows when a match is
|
||||||
found. Then enter the blocked state. */
|
found. Then enter the blocked state. */
|
||||||
vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait );
|
vTaskPlaceOnUnorderedEventList(&(pxEventBits->xTasksWaitingForBits), (uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS), xTicksToWait);
|
||||||
|
|
||||||
/* This assignment is obsolete as uxReturn will get set after
|
/* This assignment is obsolete as uxReturn will get set after
|
||||||
the task unblocks, but some compilers mistakenly generate a
|
the task unblocks, but some compilers mistakenly generate a
|
||||||
warning about uxReturn being returned without being set if the
|
warning about uxReturn being returned without being set if the
|
||||||
assignment is omitted. */
|
assignment is omitted. */
|
||||||
uxReturn = 0;
|
uxReturn = 0;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* The rendezvous bits were not set, but no block time was
|
/* The rendezvous bits were not set, but no block time was
|
||||||
specified - just return the current event bit value. */
|
specified - just return the current event bit value. */
|
||||||
uxReturn = pxEventBits->uxEventBits;
|
uxReturn = pxEventBits->uxEventBits;
|
||||||
@@ -248,14 +231,10 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
|||||||
}
|
}
|
||||||
xAlreadyYielded = xTaskResumeAll();
|
xAlreadyYielded = xTaskResumeAll();
|
||||||
|
|
||||||
if( xTicksToWait != ( TickType_t ) 0 )
|
if (xTicksToWait != (TickType_t)0) {
|
||||||
{
|
if (xAlreadyYielded == pdFALSE) {
|
||||||
if( xAlreadyYielded == pdFALSE )
|
|
||||||
{
|
|
||||||
portYIELD_WITHIN_API();
|
portYIELD_WITHIN_API();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,8 +244,7 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
|||||||
event list item, and they should now be retrieved then cleared. */
|
event list item, and they should now be retrieved then cleared. */
|
||||||
uxReturn = uxTaskResetEventItemValue();
|
uxReturn = uxTaskResetEventItemValue();
|
||||||
|
|
||||||
if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
|
if ((uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET) == (EventBits_t)0) {
|
||||||
{
|
|
||||||
/* The task timed out, just return the current event bit value. */
|
/* The task timed out, just return the current event bit value. */
|
||||||
taskENTER_CRITICAL();
|
taskENTER_CRITICAL();
|
||||||
{
|
{
|
||||||
@@ -276,21 +254,16 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
|||||||
bits it was waiting for were set, it is possible that since it
|
bits it was waiting for were set, it is possible that since it
|
||||||
unblocked another task has set the bits. If this is the case
|
unblocked another task has set the bits. If this is the case
|
||||||
then it needs to clear the bits before exiting. */
|
then it needs to clear the bits before exiting. */
|
||||||
if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor )
|
if ((uxReturn & uxBitsToWaitFor) == uxBitsToWaitFor) {
|
||||||
{
|
|
||||||
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
taskEXIT_CRITICAL();
|
taskEXIT_CRITICAL();
|
||||||
|
|
||||||
xTimeoutOccurred = pdTRUE;
|
xTimeoutOccurred = pdTRUE;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* The task unblocked because the bits were set. */
|
/* The task unblocked because the bits were set. */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,111 +272,90 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
|||||||
uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
|
uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
|
||||||
}
|
}
|
||||||
|
|
||||||
traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred );
|
traceEVENT_GROUP_SYNC_END(xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred);
|
||||||
|
|
||||||
/* Prevent compiler warnings when trace macros are not used. */
|
/* Prevent compiler warnings when trace macros are not used. */
|
||||||
( void ) xTimeoutOccurred;
|
(void)xTimeoutOccurred;
|
||||||
|
|
||||||
return uxReturn;
|
return uxReturn;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait )
|
EventBits_t xEventGroupWaitBits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait) {
|
||||||
{
|
EventGroup_t *pxEventBits = xEventGroup;
|
||||||
EventGroup_t *pxEventBits = xEventGroup;
|
EventBits_t uxReturn, uxControlBits = 0;
|
||||||
EventBits_t uxReturn, uxControlBits = 0;
|
BaseType_t xWaitConditionMet, xAlreadyYielded;
|
||||||
BaseType_t xWaitConditionMet, xAlreadyYielded;
|
BaseType_t xTimeoutOccurred = pdFALSE;
|
||||||
BaseType_t xTimeoutOccurred = pdFALSE;
|
|
||||||
|
|
||||||
/* Check the user is not attempting to wait on the bits used by the kernel
|
/* Check the user is not attempting to wait on the bits used by the kernel
|
||||||
itself, and that at least one bit is being requested. */
|
itself, and that at least one bit is being requested. */
|
||||||
configASSERT( xEventGroup );
|
configASSERT(xEventGroup);
|
||||||
configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
|
configASSERT((uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES) == 0);
|
||||||
configASSERT( uxBitsToWaitFor != 0 );
|
configASSERT(uxBitsToWaitFor != 0);
|
||||||
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
|
#if ((INCLUDE_xTaskGetSchedulerState == 1) || (configUSE_TIMERS == 1))
|
||||||
{
|
{ configASSERT(!((xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED) && (xTicksToWait != 0))); }
|
||||||
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
|
#endif
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
vTaskSuspendAll();
|
vTaskSuspendAll();
|
||||||
{
|
{
|
||||||
const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits;
|
const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits;
|
||||||
|
|
||||||
/* Check to see if the wait condition is already met or not. */
|
/* Check to see if the wait condition is already met or not. */
|
||||||
xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits );
|
xWaitConditionMet = prvTestWaitCondition(uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits);
|
||||||
|
|
||||||
if( xWaitConditionMet != pdFALSE )
|
if (xWaitConditionMet != pdFALSE) {
|
||||||
{
|
|
||||||
/* The wait condition has already been met so there is no need to
|
/* The wait condition has already been met so there is no need to
|
||||||
block. */
|
block. */
|
||||||
uxReturn = uxCurrentEventBits;
|
uxReturn = uxCurrentEventBits;
|
||||||
xTicksToWait = ( TickType_t ) 0;
|
xTicksToWait = (TickType_t)0;
|
||||||
|
|
||||||
/* Clear the wait bits if requested to do so. */
|
/* Clear the wait bits if requested to do so. */
|
||||||
if( xClearOnExit != pdFALSE )
|
if (xClearOnExit != pdFALSE) {
|
||||||
{
|
|
||||||
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
}
|
} else if (xTicksToWait == (TickType_t)0) {
|
||||||
else if( xTicksToWait == ( TickType_t ) 0 )
|
|
||||||
{
|
|
||||||
/* The wait condition has not been met, but no block time was
|
/* The wait condition has not been met, but no block time was
|
||||||
specified, so just return the current value. */
|
specified, so just return the current value. */
|
||||||
uxReturn = uxCurrentEventBits;
|
uxReturn = uxCurrentEventBits;
|
||||||
xTimeoutOccurred = pdTRUE;
|
xTimeoutOccurred = pdTRUE;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* The task is going to block to wait for its required bits to be
|
/* The task is going to block to wait for its required bits to be
|
||||||
set. uxControlBits are used to remember the specified behaviour of
|
set. uxControlBits are used to remember the specified behaviour of
|
||||||
this call to xEventGroupWaitBits() - for use when the event bits
|
this call to xEventGroupWaitBits() - for use when the event bits
|
||||||
unblock the task. */
|
unblock the task. */
|
||||||
if( xClearOnExit != pdFALSE )
|
if (xClearOnExit != pdFALSE) {
|
||||||
{
|
|
||||||
uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT;
|
uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( xWaitForAllBits != pdFALSE )
|
if (xWaitForAllBits != pdFALSE) {
|
||||||
{
|
|
||||||
uxControlBits |= eventWAIT_FOR_ALL_BITS;
|
uxControlBits |= eventWAIT_FOR_ALL_BITS;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Store the bits that the calling task is waiting for in the
|
/* Store the bits that the calling task is waiting for in the
|
||||||
task's event list item so the kernel knows when a match is
|
task's event list item so the kernel knows when a match is
|
||||||
found. Then enter the blocked state. */
|
found. Then enter the blocked state. */
|
||||||
vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait );
|
vTaskPlaceOnUnorderedEventList(&(pxEventBits->xTasksWaitingForBits), (uxBitsToWaitFor | uxControlBits), xTicksToWait);
|
||||||
|
|
||||||
/* This is obsolete as it will get set after the task unblocks, but
|
/* This is obsolete as it will get set after the task unblocks, but
|
||||||
some compilers mistakenly generate a warning about the variable
|
some compilers mistakenly generate a warning about the variable
|
||||||
being returned without being set if it is not done. */
|
being returned without being set if it is not done. */
|
||||||
uxReturn = 0;
|
uxReturn = 0;
|
||||||
|
|
||||||
traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor );
|
traceEVENT_GROUP_WAIT_BITS_BLOCK(xEventGroup, uxBitsToWaitFor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xAlreadyYielded = xTaskResumeAll();
|
xAlreadyYielded = xTaskResumeAll();
|
||||||
|
|
||||||
if( xTicksToWait != ( TickType_t ) 0 )
|
if (xTicksToWait != (TickType_t)0) {
|
||||||
{
|
if (xAlreadyYielded == pdFALSE) {
|
||||||
if( xAlreadyYielded == pdFALSE )
|
|
||||||
{
|
|
||||||
portYIELD_WITHIN_API();
|
portYIELD_WITHIN_API();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,8 +365,7 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
|||||||
event list item, and they should now be retrieved then cleared. */
|
event list item, and they should now be retrieved then cleared. */
|
||||||
uxReturn = uxTaskResetEventItemValue();
|
uxReturn = uxTaskResetEventItemValue();
|
||||||
|
|
||||||
if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
|
if ((uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET) == (EventBits_t)0) {
|
||||||
{
|
|
||||||
taskENTER_CRITICAL();
|
taskENTER_CRITICAL();
|
||||||
{
|
{
|
||||||
/* The task timed out, just return the current event bit value. */
|
/* The task timed out, just return the current event bit value. */
|
||||||
@@ -422,55 +373,46 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
|||||||
|
|
||||||
/* It is possible that the event bits were updated between this
|
/* It is possible that the event bits were updated between this
|
||||||
task leaving the Blocked state and running again. */
|
task leaving the Blocked state and running again. */
|
||||||
if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE )
|
if (prvTestWaitCondition(uxReturn, uxBitsToWaitFor, xWaitForAllBits) != pdFALSE) {
|
||||||
{
|
if (xClearOnExit != pdFALSE) {
|
||||||
if( xClearOnExit != pdFALSE )
|
|
||||||
{
|
|
||||||
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
xTimeoutOccurred = pdTRUE;
|
xTimeoutOccurred = pdTRUE;
|
||||||
}
|
}
|
||||||
taskEXIT_CRITICAL();
|
taskEXIT_CRITICAL();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* The task unblocked because the bits were set. */
|
/* The task unblocked because the bits were set. */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The task blocked so control bits may have been set. */
|
/* The task blocked so control bits may have been set. */
|
||||||
uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
|
uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
|
||||||
}
|
}
|
||||||
traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred );
|
traceEVENT_GROUP_WAIT_BITS_END(xEventGroup, uxBitsToWaitFor, xTimeoutOccurred);
|
||||||
|
|
||||||
/* Prevent compiler warnings when trace macros are not used. */
|
/* Prevent compiler warnings when trace macros are not used. */
|
||||||
( void ) xTimeoutOccurred;
|
(void)xTimeoutOccurred;
|
||||||
|
|
||||||
return uxReturn;
|
return uxReturn;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear )
|
EventBits_t xEventGroupClearBits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear) {
|
||||||
{
|
EventGroup_t *pxEventBits = xEventGroup;
|
||||||
EventGroup_t *pxEventBits = xEventGroup;
|
EventBits_t uxReturn;
|
||||||
EventBits_t uxReturn;
|
|
||||||
|
|
||||||
/* Check the user is not attempting to clear the bits used by the kernel
|
/* Check the user is not attempting to clear the bits used by the kernel
|
||||||
itself. */
|
itself. */
|
||||||
configASSERT( xEventGroup );
|
configASSERT(xEventGroup);
|
||||||
configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
|
configASSERT((uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES) == 0);
|
||||||
|
|
||||||
taskENTER_CRITICAL();
|
taskENTER_CRITICAL();
|
||||||
{
|
{
|
||||||
traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear );
|
traceEVENT_GROUP_CLEAR_BITS(xEventGroup, uxBitsToClear);
|
||||||
|
|
||||||
/* The value returned is the event group value prior to the bits being
|
/* The value returned is the event group value prior to the bits being
|
||||||
cleared. */
|
cleared. */
|
||||||
@@ -485,104 +427,87 @@ EventBits_t uxReturn;
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
|
#if ((configUSE_TRACE_FACILITY == 1) && (INCLUDE_xTimerPendFunctionCall == 1) && (configUSE_TIMERS == 1))
|
||||||
|
|
||||||
BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear )
|
BaseType_t xEventGroupClearBitsFromISR(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear) {
|
||||||
{
|
|
||||||
BaseType_t xReturn;
|
BaseType_t xReturn;
|
||||||
|
|
||||||
traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear );
|
traceEVENT_GROUP_CLEAR_BITS_FROM_ISR(xEventGroup, uxBitsToClear);
|
||||||
xReturn = xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL ); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
|
xReturn = xTimerPendFunctionCallFromISR(vEventGroupClearBitsCallback, (void *)xEventGroup, (uint32_t)uxBitsToClear,
|
||||||
|
NULL); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
|
||||||
|
|
||||||
return xReturn;
|
return xReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup )
|
EventBits_t xEventGroupGetBitsFromISR(EventGroupHandle_t xEventGroup) {
|
||||||
{
|
UBaseType_t uxSavedInterruptStatus;
|
||||||
UBaseType_t uxSavedInterruptStatus;
|
EventGroup_t const *const pxEventBits = xEventGroup;
|
||||||
EventGroup_t const * const pxEventBits = xEventGroup;
|
EventBits_t uxReturn;
|
||||||
EventBits_t uxReturn;
|
|
||||||
|
|
||||||
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
|
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
|
||||||
{
|
{ uxReturn = pxEventBits->uxEventBits; }
|
||||||
uxReturn = pxEventBits->uxEventBits;
|
portCLEAR_INTERRUPT_MASK_FROM_ISR(uxSavedInterruptStatus);
|
||||||
}
|
|
||||||
portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
|
|
||||||
|
|
||||||
return uxReturn;
|
return uxReturn;
|
||||||
} /*lint !e818 EventGroupHandle_t is a typedef used in other functions to so can't be pointer to const. */
|
} /*lint !e818 EventGroupHandle_t is a typedef used in other functions to so can't be pointer to const. */
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet )
|
EventBits_t xEventGroupSetBits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet) {
|
||||||
{
|
ListItem_t * pxListItem, *pxNext;
|
||||||
ListItem_t *pxListItem, *pxNext;
|
ListItem_t const *pxListEnd;
|
||||||
ListItem_t const *pxListEnd;
|
List_t const * pxList;
|
||||||
List_t const * pxList;
|
EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits;
|
||||||
EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits;
|
EventGroup_t * pxEventBits = xEventGroup;
|
||||||
EventGroup_t *pxEventBits = xEventGroup;
|
BaseType_t xMatchFound = pdFALSE;
|
||||||
BaseType_t xMatchFound = pdFALSE;
|
|
||||||
|
|
||||||
/* Check the user is not attempting to set the bits used by the kernel
|
/* Check the user is not attempting to set the bits used by the kernel
|
||||||
itself. */
|
itself. */
|
||||||
configASSERT( xEventGroup );
|
configASSERT(xEventGroup);
|
||||||
configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
|
configASSERT((uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES) == 0);
|
||||||
|
|
||||||
pxList = &( pxEventBits->xTasksWaitingForBits );
|
pxList = &(pxEventBits->xTasksWaitingForBits);
|
||||||
pxListEnd = listGET_END_MARKER( pxList ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
pxListEnd = listGET_END_MARKER(pxList); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
||||||
vTaskSuspendAll();
|
vTaskSuspendAll();
|
||||||
{
|
{
|
||||||
traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet );
|
traceEVENT_GROUP_SET_BITS(xEventGroup, uxBitsToSet);
|
||||||
|
|
||||||
pxListItem = listGET_HEAD_ENTRY( pxList );
|
pxListItem = listGET_HEAD_ENTRY(pxList);
|
||||||
|
|
||||||
/* Set the bits. */
|
/* Set the bits. */
|
||||||
pxEventBits->uxEventBits |= uxBitsToSet;
|
pxEventBits->uxEventBits |= uxBitsToSet;
|
||||||
|
|
||||||
/* See if the new bit value should unblock any tasks. */
|
/* See if the new bit value should unblock any tasks. */
|
||||||
while( pxListItem != pxListEnd )
|
while (pxListItem != pxListEnd) {
|
||||||
{
|
pxNext = listGET_NEXT(pxListItem);
|
||||||
pxNext = listGET_NEXT( pxListItem );
|
uxBitsWaitedFor = listGET_LIST_ITEM_VALUE(pxListItem);
|
||||||
uxBitsWaitedFor = listGET_LIST_ITEM_VALUE( pxListItem );
|
|
||||||
xMatchFound = pdFALSE;
|
xMatchFound = pdFALSE;
|
||||||
|
|
||||||
/* Split the bits waited for from the control bits. */
|
/* Split the bits waited for from the control bits. */
|
||||||
uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES;
|
uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES;
|
||||||
uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES;
|
uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES;
|
||||||
|
|
||||||
if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( EventBits_t ) 0 )
|
if ((uxControlBits & eventWAIT_FOR_ALL_BITS) == (EventBits_t)0) {
|
||||||
{
|
|
||||||
/* Just looking for single bit being set. */
|
/* Just looking for single bit being set. */
|
||||||
if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( EventBits_t ) 0 )
|
if ((uxBitsWaitedFor & pxEventBits->uxEventBits) != (EventBits_t)0) {
|
||||||
{
|
|
||||||
xMatchFound = pdTRUE;
|
xMatchFound = pdTRUE;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
}
|
} else if ((uxBitsWaitedFor & pxEventBits->uxEventBits) == uxBitsWaitedFor) {
|
||||||
else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor )
|
|
||||||
{
|
|
||||||
/* All bits are set. */
|
/* All bits are set. */
|
||||||
xMatchFound = pdTRUE;
|
xMatchFound = pdTRUE;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Need all bits to be set, but not all the bits were set. */
|
/* Need all bits to be set, but not all the bits were set. */
|
||||||
}
|
}
|
||||||
|
|
||||||
if( xMatchFound != pdFALSE )
|
if (xMatchFound != pdFALSE) {
|
||||||
{
|
|
||||||
/* The bits match. Should the bits be cleared on exit? */
|
/* The bits match. Should the bits be cleared on exit? */
|
||||||
if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( EventBits_t ) 0 )
|
if ((uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT) != (EventBits_t)0) {
|
||||||
{
|
|
||||||
uxBitsToClear |= uxBitsWaitedFor;
|
uxBitsToClear |= uxBitsWaitedFor;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,7 +516,7 @@ BaseType_t xMatchFound = pdFALSE;
|
|||||||
eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows
|
eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows
|
||||||
that is was unblocked due to its required bits matching, rather
|
that is was unblocked due to its required bits matching, rather
|
||||||
than because it timed out. */
|
than because it timed out. */
|
||||||
vTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET );
|
vTaskRemoveFromUnorderedEventList(pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move onto the next list item. Note pxListItem->pxNext is not
|
/* Move onto the next list item. Note pxListItem->pxNext is not
|
||||||
@@ -604,97 +529,80 @@ BaseType_t xMatchFound = pdFALSE;
|
|||||||
bit was set in the control word. */
|
bit was set in the control word. */
|
||||||
pxEventBits->uxEventBits &= ~uxBitsToClear;
|
pxEventBits->uxEventBits &= ~uxBitsToClear;
|
||||||
}
|
}
|
||||||
( void ) xTaskResumeAll();
|
(void)xTaskResumeAll();
|
||||||
|
|
||||||
return pxEventBits->uxEventBits;
|
return pxEventBits->uxEventBits;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vEventGroupDelete( EventGroupHandle_t xEventGroup )
|
void vEventGroupDelete(EventGroupHandle_t xEventGroup) {
|
||||||
{
|
EventGroup_t *pxEventBits = xEventGroup;
|
||||||
EventGroup_t *pxEventBits = xEventGroup;
|
const List_t *pxTasksWaitingForBits = &(pxEventBits->xTasksWaitingForBits);
|
||||||
const List_t *pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
|
|
||||||
|
|
||||||
vTaskSuspendAll();
|
vTaskSuspendAll();
|
||||||
{
|
{
|
||||||
traceEVENT_GROUP_DELETE( xEventGroup );
|
traceEVENT_GROUP_DELETE(xEventGroup);
|
||||||
|
|
||||||
while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 )
|
while (listCURRENT_LIST_LENGTH(pxTasksWaitingForBits) > (UBaseType_t)0) {
|
||||||
{
|
|
||||||
/* Unblock the task, returning 0 as the event list is being deleted
|
/* Unblock the task, returning 0 as the event list is being deleted
|
||||||
and cannot therefore have any bits set. */
|
and cannot therefore have any bits set. */
|
||||||
configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( const ListItem_t * ) &( pxTasksWaitingForBits->xListEnd ) );
|
configASSERT(pxTasksWaitingForBits->xListEnd.pxNext != (const ListItem_t *)&(pxTasksWaitingForBits->xListEnd));
|
||||||
vTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, eventUNBLOCKED_DUE_TO_BIT_SET );
|
vTaskRemoveFromUnorderedEventList(pxTasksWaitingForBits->xListEnd.pxNext, eventUNBLOCKED_DUE_TO_BIT_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )
|
#if ((configSUPPORT_DYNAMIC_ALLOCATION == 1) && (configSUPPORT_STATIC_ALLOCATION == 0))
|
||||||
{
|
{
|
||||||
/* The event group can only have been allocated dynamically - free
|
/* The event group can only have been allocated dynamically - free
|
||||||
it again. */
|
it again. */
|
||||||
vPortFree( pxEventBits );
|
vPortFree(pxEventBits);
|
||||||
}
|
}
|
||||||
#elif( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
|
#elif ((configSUPPORT_DYNAMIC_ALLOCATION == 1) && (configSUPPORT_STATIC_ALLOCATION == 1))
|
||||||
{
|
{
|
||||||
/* The event group could have been allocated statically or
|
/* The event group could have been allocated statically or
|
||||||
dynamically, so check before attempting to free the memory. */
|
dynamically, so check before attempting to free the memory. */
|
||||||
if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdFALSE )
|
if (pxEventBits->ucStaticallyAllocated == (uint8_t)pdFALSE) {
|
||||||
{
|
vPortFree(pxEventBits);
|
||||||
vPortFree( pxEventBits );
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
|
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
|
||||||
}
|
}
|
||||||
( void ) xTaskResumeAll();
|
(void)xTaskResumeAll();
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/* For internal use only - execute a 'set bits' command that was pended from
|
/* For internal use only - execute a 'set bits' command that was pended from
|
||||||
an interrupt. */
|
an interrupt. */
|
||||||
void vEventGroupSetBitsCallback( void *pvEventGroup, const uint32_t ulBitsToSet )
|
void vEventGroupSetBitsCallback(void *pvEventGroup, const uint32_t ulBitsToSet) {
|
||||||
{
|
(void)xEventGroupSetBits(pvEventGroup, (EventBits_t)ulBitsToSet); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */
|
||||||
( void ) xEventGroupSetBits( pvEventGroup, ( EventBits_t ) ulBitsToSet ); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/* For internal use only - execute a 'clear bits' command that was pended from
|
/* For internal use only - execute a 'clear bits' command that was pended from
|
||||||
an interrupt. */
|
an interrupt. */
|
||||||
void vEventGroupClearBitsCallback( void *pvEventGroup, const uint32_t ulBitsToClear )
|
void vEventGroupClearBitsCallback(void *pvEventGroup, const uint32_t ulBitsToClear) {
|
||||||
{
|
(void)xEventGroupClearBits(pvEventGroup, (EventBits_t)ulBitsToClear); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */
|
||||||
( void ) xEventGroupClearBits( pvEventGroup, ( EventBits_t ) ulBitsToClear ); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits )
|
static BaseType_t prvTestWaitCondition(const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits) {
|
||||||
{
|
BaseType_t xWaitConditionMet = pdFALSE;
|
||||||
BaseType_t xWaitConditionMet = pdFALSE;
|
|
||||||
|
|
||||||
if( xWaitForAllBits == pdFALSE )
|
if (xWaitForAllBits == pdFALSE) {
|
||||||
{
|
|
||||||
/* Task only has to wait for one bit within uxBitsToWaitFor to be
|
/* Task only has to wait for one bit within uxBitsToWaitFor to be
|
||||||
set. Is one already set? */
|
set. Is one already set? */
|
||||||
if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( EventBits_t ) 0 )
|
if ((uxCurrentEventBits & uxBitsToWaitFor) != (EventBits_t)0) {
|
||||||
{
|
|
||||||
xWaitConditionMet = pdTRUE;
|
xWaitConditionMet = pdTRUE;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Task has to wait for all the bits in uxBitsToWaitFor to be set.
|
/* Task has to wait for all the bits in uxBitsToWaitFor to be set.
|
||||||
Are they set already? */
|
Are they set already? */
|
||||||
if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor )
|
if ((uxCurrentEventBits & uxBitsToWaitFor) == uxBitsToWaitFor) {
|
||||||
{
|
|
||||||
xWaitConditionMet = pdTRUE;
|
xWaitConditionMet = pdTRUE;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -703,51 +611,47 @@ BaseType_t xWaitConditionMet = pdFALSE;
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
|
#if ((configUSE_TRACE_FACILITY == 1) && (INCLUDE_xTimerPendFunctionCall == 1) && (configUSE_TIMERS == 1))
|
||||||
|
|
||||||
BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken )
|
BaseType_t xEventGroupSetBitsFromISR(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken) {
|
||||||
{
|
|
||||||
BaseType_t xReturn;
|
BaseType_t xReturn;
|
||||||
|
|
||||||
traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet );
|
traceEVENT_GROUP_SET_BITS_FROM_ISR(xEventGroup, uxBitsToSet);
|
||||||
xReturn = xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken ); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
|
xReturn = xTimerPendFunctionCallFromISR(
|
||||||
|
vEventGroupSetBitsCallback, (void *)xEventGroup, (uint32_t)uxBitsToSet,
|
||||||
|
pxHigherPriorityTaskWoken); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
|
||||||
|
|
||||||
return xReturn;
|
return xReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
#if (configUSE_TRACE_FACILITY == 1)
|
#if (configUSE_TRACE_FACILITY == 1)
|
||||||
|
|
||||||
UBaseType_t uxEventGroupGetNumber( void* xEventGroup )
|
UBaseType_t uxEventGroupGetNumber(void *xEventGroup) {
|
||||||
{
|
|
||||||
UBaseType_t xReturn;
|
UBaseType_t xReturn;
|
||||||
EventGroup_t const *pxEventBits = ( EventGroup_t * ) xEventGroup; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
|
EventGroup_t const *pxEventBits
|
||||||
|
= (EventGroup_t *)xEventGroup; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
|
||||||
|
|
||||||
if( xEventGroup == NULL )
|
if (xEventGroup == NULL) {
|
||||||
{
|
|
||||||
xReturn = 0;
|
xReturn = 0;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
xReturn = pxEventBits->uxEventGroupNumber;
|
xReturn = pxEventBits->uxEventGroupNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
return xReturn;
|
return xReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* configUSE_TRACE_FACILITY */
|
#endif /* configUSE_TRACE_FACILITY */
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
#if ( configUSE_TRACE_FACILITY == 1 )
|
#if (configUSE_TRACE_FACILITY == 1)
|
||||||
|
|
||||||
void vEventGroupSetNumber( void * xEventGroup, UBaseType_t uxEventGroupNumber )
|
void vEventGroupSetNumber(void *xEventGroup, UBaseType_t uxEventGroupNumber) {
|
||||||
{
|
((EventGroup_t *)xEventGroup)->uxEventGroupNumber
|
||||||
( ( EventGroup_t * ) xEventGroup )->uxEventGroupNumber = uxEventGroupNumber; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
|
= uxEventGroupNumber; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* configUSE_TRACE_FACILITY */
|
#endif /* configUSE_TRACE_FACILITY */
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,21 +25,19 @@
|
|||||||
* 1 tab == 4 spaces!
|
* 1 tab == 4 spaces!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "FreeRTOS.h"
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
/*-----------------------------------------------------------
|
/*-----------------------------------------------------------
|
||||||
* PUBLIC LIST API documented in list.h
|
* PUBLIC LIST API documented in list.h
|
||||||
*----------------------------------------------------------*/
|
*----------------------------------------------------------*/
|
||||||
|
|
||||||
void vListInitialise( List_t * const pxList )
|
void vListInitialise(List_t *const pxList) {
|
||||||
{
|
|
||||||
/* The list structure contains a list item which is used to mark the
|
/* The list structure contains a list item which is used to mark the
|
||||||
end of the list. To initialise the list the list end is inserted
|
end of the list. To initialise the list the list end is inserted
|
||||||
as the only list entry. */
|
as the only list entry. */
|
||||||
pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
pxList->pxIndex = (ListItem_t *)&(pxList->xListEnd); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
||||||
|
|
||||||
/* The list end value is the highest possible value in the list to
|
/* The list end value is the highest possible value in the list to
|
||||||
ensure it remains at the end of the list. */
|
ensure it remains at the end of the list. */
|
||||||
@@ -47,39 +45,37 @@ void vListInitialise( List_t * const pxList )
|
|||||||
|
|
||||||
/* The list end next and previous pointers point to itself so we know
|
/* The list end next and previous pointers point to itself so we know
|
||||||
when the list is empty. */
|
when the list is empty. */
|
||||||
pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
pxList->xListEnd.pxNext = (ListItem_t *)&(pxList->xListEnd); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
||||||
pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );/*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
pxList->xListEnd.pxPrevious = (ListItem_t *)&(pxList->xListEnd); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
||||||
|
|
||||||
pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
|
pxList->uxNumberOfItems = (UBaseType_t)0U;
|
||||||
|
|
||||||
/* Write known values into the list if
|
/* Write known values into the list if
|
||||||
configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
|
configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
|
||||||
listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );
|
listSET_LIST_INTEGRITY_CHECK_1_VALUE(pxList);
|
||||||
listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );
|
listSET_LIST_INTEGRITY_CHECK_2_VALUE(pxList);
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vListInitialiseItem( ListItem_t * const pxItem )
|
void vListInitialiseItem(ListItem_t *const pxItem) {
|
||||||
{
|
|
||||||
/* Make sure the list item is not recorded as being on a list. */
|
/* Make sure the list item is not recorded as being on a list. */
|
||||||
pxItem->pxContainer = NULL;
|
pxItem->pxContainer = NULL;
|
||||||
|
|
||||||
/* Write known values into the list item if
|
/* Write known values into the list item if
|
||||||
configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
|
configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
|
||||||
listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
|
listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE(pxItem);
|
||||||
listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
|
listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE(pxItem);
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )
|
void vListInsertEnd(List_t *const pxList, ListItem_t *const pxNewListItem) {
|
||||||
{
|
ListItem_t *const pxIndex = pxList->pxIndex;
|
||||||
ListItem_t * const pxIndex = pxList->pxIndex;
|
|
||||||
|
|
||||||
/* Only effective when configASSERT() is also defined, these tests may catch
|
/* Only effective when configASSERT() is also defined, these tests may catch
|
||||||
the list data structures being overwritten in memory. They will not catch
|
the list data structures being overwritten in memory. They will not catch
|
||||||
data errors caused by incorrect configuration or use of FreeRTOS. */
|
data errors caused by incorrect configuration or use of FreeRTOS. */
|
||||||
listTEST_LIST_INTEGRITY( pxList );
|
listTEST_LIST_INTEGRITY(pxList);
|
||||||
listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
|
listTEST_LIST_ITEM_INTEGRITY(pxNewListItem);
|
||||||
|
|
||||||
/* Insert a new list item into pxList, but rather than sort the list,
|
/* Insert a new list item into pxList, but rather than sort the list,
|
||||||
makes the new list item the last item to be removed by a call to
|
makes the new list item the last item to be removed by a call to
|
||||||
@@ -96,20 +92,19 @@ ListItem_t * const pxIndex = pxList->pxIndex;
|
|||||||
/* Remember which list the item is in. */
|
/* Remember which list the item is in. */
|
||||||
pxNewListItem->pxContainer = pxList;
|
pxNewListItem->pxContainer = pxList;
|
||||||
|
|
||||||
( pxList->uxNumberOfItems )++;
|
(pxList->uxNumberOfItems)++;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )
|
void vListInsert(List_t *const pxList, ListItem_t *const pxNewListItem) {
|
||||||
{
|
ListItem_t * pxIterator;
|
||||||
ListItem_t *pxIterator;
|
const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
|
||||||
const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
|
|
||||||
|
|
||||||
/* Only effective when configASSERT() is also defined, these tests may catch
|
/* Only effective when configASSERT() is also defined, these tests may catch
|
||||||
the list data structures being overwritten in memory. They will not catch
|
the list data structures being overwritten in memory. They will not catch
|
||||||
data errors caused by incorrect configuration or use of FreeRTOS. */
|
data errors caused by incorrect configuration or use of FreeRTOS. */
|
||||||
listTEST_LIST_INTEGRITY( pxList );
|
listTEST_LIST_INTEGRITY(pxList);
|
||||||
listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
|
listTEST_LIST_ITEM_INTEGRITY(pxNewListItem);
|
||||||
|
|
||||||
/* Insert the new list item into the list, sorted in xItemValue order.
|
/* Insert the new list item into the list, sorted in xItemValue order.
|
||||||
|
|
||||||
@@ -119,12 +114,9 @@ const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
|
|||||||
share of the CPU. However, if the xItemValue is the same as the back marker
|
share of the CPU. However, if the xItemValue is the same as the back marker
|
||||||
the iteration loop below will not end. Therefore the value is checked
|
the iteration loop below will not end. Therefore the value is checked
|
||||||
first, and the algorithm slightly modified if necessary. */
|
first, and the algorithm slightly modified if necessary. */
|
||||||
if( xValueOfInsertion == portMAX_DELAY )
|
if (xValueOfInsertion == portMAX_DELAY) {
|
||||||
{
|
|
||||||
pxIterator = pxList->xListEnd.pxPrevious;
|
pxIterator = pxList->xListEnd.pxPrevious;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* *** NOTE ***********************************************************
|
/* *** NOTE ***********************************************************
|
||||||
If you find your application is crashing here then likely causes are
|
If you find your application is crashing here then likely causes are
|
||||||
listed below. In addition see https://www.freertos.org/FAQHelp.html for
|
listed below. In addition see https://www.freertos.org/FAQHelp.html for
|
||||||
@@ -147,7 +139,10 @@ const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
|
|||||||
before vTaskStartScheduler() has been called?).
|
before vTaskStartScheduler() has been called?).
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. *//*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */
|
for (pxIterator = (ListItem_t *)&(pxList->xListEnd); pxIterator->pxNext->xItemValue <= xValueOfInsertion;
|
||||||
|
pxIterator
|
||||||
|
= pxIterator->pxNext) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */ /*lint !e440 The iterator moves to a
|
||||||
|
different value, not xValueOfInsertion. */
|
||||||
{
|
{
|
||||||
/* There is nothing to do here, just iterating to the wanted
|
/* There is nothing to do here, just iterating to the wanted
|
||||||
insertion position. */
|
insertion position. */
|
||||||
@@ -163,15 +158,14 @@ const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
|
|||||||
item later. */
|
item later. */
|
||||||
pxNewListItem->pxContainer = pxList;
|
pxNewListItem->pxContainer = pxList;
|
||||||
|
|
||||||
( pxList->uxNumberOfItems )++;
|
(pxList->uxNumberOfItems)++;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
|
UBaseType_t uxListRemove(ListItem_t *const pxItemToRemove) {
|
||||||
{
|
/* The list item knows which list it is in. Obtain the list from the list
|
||||||
/* The list item knows which list it is in. Obtain the list from the list
|
item. */
|
||||||
item. */
|
List_t *const pxList = pxItemToRemove->pxContainer;
|
||||||
List_t * const pxList = pxItemToRemove->pxContainer;
|
|
||||||
|
|
||||||
pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
|
pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
|
||||||
pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
|
pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
|
||||||
@@ -180,19 +174,15 @@ List_t * const pxList = pxItemToRemove->pxContainer;
|
|||||||
mtCOVERAGE_TEST_DELAY();
|
mtCOVERAGE_TEST_DELAY();
|
||||||
|
|
||||||
/* Make sure the index is left pointing to a valid item. */
|
/* Make sure the index is left pointing to a valid item. */
|
||||||
if( pxList->pxIndex == pxItemToRemove )
|
if (pxList->pxIndex == pxItemToRemove) {
|
||||||
{
|
|
||||||
pxList->pxIndex = pxItemToRemove->pxPrevious;
|
pxList->pxIndex = pxItemToRemove->pxPrevious;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
|
|
||||||
pxItemToRemove->pxContainer = NULL;
|
pxItemToRemove->pxContainer = NULL;
|
||||||
( pxList->uxNumberOfItems )--;
|
(pxList->uxNumberOfItems)--;
|
||||||
|
|
||||||
return pxList->uxNumberOfItems;
|
return pxList->uxNumberOfItems;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|||||||
2145
source/Middlewares/Third_Party/FreeRTOS/Source/queue.c
vendored
2145
source/Middlewares/Third_Party/FreeRTOS/Source/queue.c
vendored
File diff suppressed because it is too large
Load Diff
3564
source/Middlewares/Third_Party/FreeRTOS/Source/tasks.c
vendored
3564
source/Middlewares/Third_Party/FreeRTOS/Source/tasks.c
vendored
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user