Rebalance ram
This commit is contained in:
@@ -34,6 +34,7 @@ public:
|
||||
|
||||
private:
|
||||
static I2C_HandleTypeDef *i2c;
|
||||
static void I2C1_ClearBusyFlagErratum();
|
||||
static SemaphoreHandle_t I2CSemaphore;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <stdint.h>
|
||||
#include "stm32f1xx_hal.h"
|
||||
#define SETTINGSVERSION \
|
||||
0x16 /*Change this if you change the struct below to prevent people getting \
|
||||
0x18 /*Change this if you change the struct below to prevent people getting \
|
||||
out of sync*/
|
||||
|
||||
/*
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Created on: 14Apr.,2018
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#include "hardware.h"
|
||||
#include "FRToSI2C.hpp"
|
||||
#define I2CUSESDMA
|
||||
I2C_HandleTypeDef* FRToSI2C::i2c;
|
||||
@@ -12,14 +12,13 @@ SemaphoreHandle_t FRToSI2C::I2CSemaphore;
|
||||
void FRToSI2C::CpltCallback() {
|
||||
i2c->State = HAL_I2C_STATE_READY; // Force state reset (even if tx error)
|
||||
if (I2CSemaphore) {
|
||||
|
||||
xSemaphoreGiveFromISR(I2CSemaphore, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
||||
uint16_t MemAddSize, uint8_t* pData, uint16_t Size) {
|
||||
#ifdef I2CUSESDMA
|
||||
|
||||
if (I2CSemaphore == NULL) {
|
||||
// no RToS, run blocking code
|
||||
HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
@@ -29,17 +28,23 @@ void FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
||||
// Get the mutex so we can use the I2C port
|
||||
// Wait up to 1 second for the mutex
|
||||
if (xSemaphoreTake(I2CSemaphore, (TickType_t)50) == pdTRUE) {
|
||||
if (HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
5000) != HAL_OK) {
|
||||
}
|
||||
#ifdef I2CUSESDMA
|
||||
if (HAL_I2C_Mem_Read_DMA(i2c, DevAddress, MemAddress, MemAddSize,
|
||||
pData, Size) != HAL_OK) {
|
||||
|
||||
I2C1_ClearBusyFlagErratum();
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
}
|
||||
#else
|
||||
|
||||
HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
5000);
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
#endif
|
||||
} else {
|
||||
}
|
||||
}
|
||||
#else
|
||||
HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
5000);
|
||||
#endif
|
||||
|
||||
}
|
||||
void FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) {
|
||||
Mem_Write(address, reg, I2C_MEMADD_SIZE_8BIT, &data, 1);
|
||||
@@ -52,7 +57,7 @@ uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) {
|
||||
}
|
||||
void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
||||
uint16_t MemAddSize, uint8_t* pData, uint16_t Size) {
|
||||
#ifdef I2CUSESDMA
|
||||
|
||||
if (I2CSemaphore == NULL) {
|
||||
// no RToS, run blocking code
|
||||
HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
@@ -62,22 +67,26 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
||||
// Get the mutex so we can use the I2C port
|
||||
// Wait up to 1 second for the mutex
|
||||
if (xSemaphoreTake(I2CSemaphore, (TickType_t)50) == pdTRUE) {
|
||||
#ifdef I2CUSESDMA
|
||||
if (HAL_I2C_Mem_Write_DMA(i2c, DevAddress, MemAddress, MemAddSize,
|
||||
pData, Size) != HAL_OK) {
|
||||
|
||||
I2C1_ClearBusyFlagErratum();
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
}
|
||||
#else
|
||||
if (HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData,
|
||||
Size, 5000) != HAL_OK) {
|
||||
}
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
|
||||
#endif
|
||||
} else {
|
||||
}
|
||||
}
|
||||
#else
|
||||
HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
5000);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t* pData, uint16_t Size) {
|
||||
#ifdef I2CUSESDMA
|
||||
if (I2CSemaphore == NULL) {
|
||||
// no RToS, run blocking code
|
||||
HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000);
|
||||
@@ -86,13 +95,91 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t* pData, uint16_t Size) {
|
||||
// Get the mutex so we can use the I2C port
|
||||
// Wait up to 1 second for the mutex
|
||||
if (xSemaphoreTake(I2CSemaphore, (TickType_t)50) == pdTRUE) {
|
||||
if (HAL_I2C_Master_Transmit_DMA(i2c, DevAddress, pData, Size) != HAL_OK) {
|
||||
}
|
||||
// xSemaphoreGive(I2CSemaphore);
|
||||
} else {
|
||||
}
|
||||
#ifdef I2CUSESDMA
|
||||
|
||||
if (HAL_I2C_Master_Transmit_DMA(i2c, DevAddress, pData, Size)
|
||||
!= HAL_OK) {
|
||||
|
||||
I2C1_ClearBusyFlagErratum();
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
|
||||
}
|
||||
#else
|
||||
HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000);
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
#endif
|
||||
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FRToSI2C::I2C1_ClearBusyFlagErratum() {
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
int timeout = 100;
|
||||
int timeout_cnt = 0;
|
||||
|
||||
// 1. Clear PE bit.
|
||||
i2c->Instance->CR1 &= ~(0x0001);
|
||||
/**I2C1 GPIO Configuration
|
||||
PB6 ------> I2C1_SCL
|
||||
PB7 ------> I2C1_SDA
|
||||
*/
|
||||
// 2. Configure the SCL and SDA I/Os as General Purpose Output Open-Drain, High level (Write 1 to GPIOx_ODR).
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
|
||||
GPIO_InitStruct.Pin = SCL_Pin;
|
||||
HAL_GPIO_Init(SCL_GPIO_Port, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(SCL_GPIO_Port, SCL_Pin, GPIO_PIN_SET);
|
||||
|
||||
GPIO_InitStruct.Pin = SDA_Pin;
|
||||
HAL_GPIO_Init(SDA_GPIO_Port, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_SET);
|
||||
|
||||
while (GPIO_PIN_SET != HAL_GPIO_ReadPin(SDA_GPIO_Port, SDA_Pin)) {
|
||||
//Move clock to release I2C
|
||||
HAL_GPIO_WritePin(SCL_GPIO_Port, SCL_Pin, GPIO_PIN_RESET);
|
||||
asm("nop");
|
||||
asm("nop");
|
||||
asm("nop");
|
||||
asm("nop");
|
||||
HAL_GPIO_WritePin(SCL_GPIO_Port, SCL_Pin, GPIO_PIN_SET);
|
||||
|
||||
timeout_cnt++;
|
||||
if (timeout_cnt > timeout)
|
||||
return;
|
||||
}
|
||||
|
||||
// 12. Configure the SCL and SDA I/Os as Alternate function Open-Drain.
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
|
||||
GPIO_InitStruct.Pin = SCL_Pin;
|
||||
HAL_GPIO_Init(SCL_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = SDA_Pin;
|
||||
HAL_GPIO_Init(SDA_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
HAL_GPIO_WritePin(SCL_GPIO_Port, SCL_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_SET);
|
||||
|
||||
// 13. Set SWRST bit in I2Cx_CR1 register.
|
||||
i2c->Instance->CR1 |= 0x8000;
|
||||
|
||||
asm("nop");
|
||||
|
||||
// 14. Clear SWRST bit in I2Cx_CR1 register.
|
||||
i2c->Instance->CR1 &= ~0x8000;
|
||||
|
||||
asm("nop");
|
||||
|
||||
// 15. Enable the I2C peripheral by setting the PE bit in I2Cx_CR1 register
|
||||
i2c->Instance->CR1 |= 0x0001;
|
||||
|
||||
// Call initialization function.
|
||||
HAL_I2C_Init(i2c);
|
||||
}
|
||||
|
||||
@@ -361,13 +361,13 @@ static void MX_DMA_Init(void) {
|
||||
|
||||
/* DMA interrupt init */
|
||||
/* DMA1_Channel1_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 15, 0);
|
||||
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
|
||||
/* DMA1_Channel6_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 15, 0);
|
||||
HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
|
||||
/* DMA1_Channel7_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 15, 0);
|
||||
HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ int main(void) {
|
||||
|
||||
/* Create the thread(s) */
|
||||
/* definition and creation of GUITask */
|
||||
osThreadDef(GUITask, startGUITask, osPriorityBelowNormal, 0, 4 * 1024 / 4);
|
||||
osThreadDef(GUITask, startGUITask, osPriorityBelowNormal, 0, 5 * 1024 / 4);
|
||||
GUITaskHandle = osThreadCreate(osThread(GUITask), NULL);
|
||||
|
||||
/* definition and creation of PIDTask */
|
||||
@@ -77,7 +77,7 @@ int main(void) {
|
||||
PIDTaskHandle = osThreadCreate(osThread(PIDTask), NULL);
|
||||
if (PCBVersion < 3) {
|
||||
/* definition and creation of MOVTask */
|
||||
osThreadDef(MOVTask, startMOVTask, osPriorityNormal, 0, 2 * 1024 / 4);
|
||||
osThreadDef(MOVTask, startMOVTask, osPriorityNormal, 0, 3 * 1024 / 4);
|
||||
MOVTaskHandle = osThreadCreate(osThread(MOVTask), NULL);
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ static void gui_drawBatteryIcon() {
|
||||
// Range is 42 -> 33 = 9 steps therefore we will use battery 1-10
|
||||
if (cellV < 33)
|
||||
cellV = 33;
|
||||
cellV -= 33;// Should leave us a number of 0-9
|
||||
cellV -= 33; // Should leave us a number of 0-9
|
||||
if (cellV > 9)
|
||||
cellV = 9;
|
||||
OLED::drawBattery(cellV + 1);
|
||||
@@ -282,7 +282,7 @@ static void gui_drawBatteryIcon() {
|
||||
// If <9V then show single digit, if not show duals
|
||||
uint8_t V = getInputVoltageX10(systemSettings.voltageDiv, 0);
|
||||
if (V % 10 >= 5)
|
||||
V = V / 10 + 1; // round up
|
||||
V = V / 10 + 1;// round up
|
||||
else
|
||||
V = V / 10;
|
||||
if (V >= 10) {
|
||||
@@ -501,6 +501,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
|
||||
* --> Double button to exit
|
||||
*/
|
||||
bool boostModeOn = false;
|
||||
uint8_t badTipCounter = 0;
|
||||
uint32_t sleepThres = 0;
|
||||
if (systemSettings.SleepTime < 6)
|
||||
sleepThres = systemSettings.SleepTime * 10 * 100;
|
||||
@@ -549,14 +550,10 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
|
||||
OLED::clearScreen();
|
||||
OLED::setFont(0);
|
||||
uint16_t tipTemp = getTipRawTemp(0);
|
||||
if (tipTemp > 32752) {
|
||||
OLED::print(BadTipString);
|
||||
OLED::refresh();
|
||||
currentlyActiveTemperatureTarget = 0;
|
||||
waitForButtonPress();
|
||||
currentlyActiveTemperatureTarget = 0;
|
||||
return;
|
||||
if (tipTemp > 32760) {
|
||||
badTipCounter++;
|
||||
} else {
|
||||
badTipCounter = 0;
|
||||
if (systemSettings.detailedSoldering) {
|
||||
OLED::setFont(1);
|
||||
OLED::print(SolderingAdvancedPowerPrompt); // Power:
|
||||
@@ -615,6 +612,14 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (badTipCounter > 128) {
|
||||
OLED::print(BadTipString);
|
||||
OLED::refresh();
|
||||
currentlyActiveTemperatureTarget = 0;
|
||||
waitForButtonPress();
|
||||
currentlyActiveTemperatureTarget = 0;
|
||||
return;
|
||||
}
|
||||
OLED::refresh();
|
||||
|
||||
// Update the setpoints for the temperature
|
||||
@@ -944,10 +949,11 @@ void startPIDTask(void const *argument __unused) {
|
||||
if (currentlyActiveTemperatureTarget) {
|
||||
// Cap the max set point to 450C
|
||||
if (currentlyActiveTemperatureTarget > ctoTipMeasurement(450)) {
|
||||
//Maximum allowed output
|
||||
currentlyActiveTemperatureTarget = ctoTipMeasurement(450);
|
||||
}
|
||||
if (currentlyActiveTemperatureTarget > 32500) {
|
||||
currentlyActiveTemperatureTarget = 32500;
|
||||
} else if (currentlyActiveTemperatureTarget > 32400) {
|
||||
//Cap to max adc reading
|
||||
currentlyActiveTemperatureTarget = 32400;
|
||||
}
|
||||
|
||||
// As we get close to our target, temp noise causes the system
|
||||
@@ -1035,7 +1041,7 @@ void startMOVTask(void const *argument __unused) {
|
||||
while (pidTaskNotification == 0)
|
||||
osDelay(20); // To ensure we return after idealQCVoltage/tip resistance
|
||||
|
||||
seekQC(idealQCVoltage, systemSettings.voltageDiv); // this will move the QC output to the preferred voltage to start with
|
||||
seekQC(idealQCVoltage, systemSettings.voltageDiv);// this will move the QC output to the preferred voltage to start with
|
||||
|
||||
#else
|
||||
osDelay(250); // wait for accelerometer to stabilize
|
||||
@@ -1185,9 +1191,13 @@ void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
||||
FRToSI2C::CpltCallback();
|
||||
}
|
||||
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c __unused) {
|
||||
asm("bkpt");
|
||||
|
||||
FRToSI2C::CpltCallback();
|
||||
}
|
||||
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
||||
asm("bkpt");
|
||||
|
||||
FRToSI2C::CpltCallback();
|
||||
}
|
||||
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
||||
@@ -1195,6 +1205,7 @@ void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
||||
}
|
||||
void vApplicationStackOverflowHook(xTaskHandle *pxTask __unused,
|
||||
signed portCHAR *pcTaskName __unused) {
|
||||
asm("bkpt");
|
||||
// We dont have a good way to handle a stack overflow at this point in time
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) {
|
||||
GPIO_InitStruct.Pin = SCL_Pin | SDA_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* Peripheral clock enable */
|
||||
|
||||
Reference in New Issue
Block a user