diff --git a/workspace/TS100/.cproject b/workspace/TS100/.cproject
index c9b40cb8..1f09a218 100644
--- a/workspace/TS100/.cproject
+++ b/workspace/TS100/.cproject
@@ -110,120 +110,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/workspace/TS100/.settings/language.settings.xml b/workspace/TS100/.settings/language.settings.xml
index 1765bf7f..74f0690e 100644
--- a/workspace/TS100/.settings/language.settings.xml
+++ b/workspace/TS100/.settings/language.settings.xml
@@ -12,16 +12,4 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/workspace/TS100/TS100.cfg b/workspace/TS100/TS100.cfg
new file mode 100644
index 00000000..c9d72fe4
--- /dev/null
+++ b/workspace/TS100/TS100.cfg
@@ -0,0 +1,27 @@
+# This is an ts100 board with a single STM32F103T8Ux chip
+#
+# Generated by System Workbench for STM32
+# Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s)
+
+source [find interface/stlink.cfg]
+
+set WORKAREASIZE 0x5000
+
+transport select "hla_swd"
+
+set CHIPNAME STM32F103T8Ux
+
+# Enable debug when in low power modes
+set ENABLE_LOW_POWER 1
+
+# Stop Watchdog counters when halt
+set STOP_WATCHDOG 1
+
+# STlink Debug clock frequency
+set CLOCK_FREQ 950
+
+# use software system reset
+reset_config none
+set CONNECT_UNDER_RESET 0
+
+source [find target/stm32f1x.cfg]
diff --git a/workspace/TS100/inc/FRToSI2C.hpp b/workspace/TS100/inc/FRToSI2C.hpp
index e0a19f1d..0bf52ebd 100644
--- a/workspace/TS100/inc/FRToSI2C.hpp
+++ b/workspace/TS100/inc/FRToSI2C.hpp
@@ -13,20 +13,22 @@
class FRToSI2C {
public:
FRToSI2C(I2C_HandleTypeDef* i2chandle);
+ void FRToSInit();
void MasterTxCpltCallback(); //Normal Tx Callback
void MemRxCpltCallback(); //Callback from memory read cycles
void MemTxCpltCallback(); //Callback from memory write cycles
void Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize,
- uint8_t *pData, uint16_t Size);
- void Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize,
- uint8_t *pData, uint16_t Size);
+ uint8_t *pData, uint16_t Size);
+ void Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
+ uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
void Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size);
-
private:
+ bool RToSUP=false;
I2C_HandleTypeDef* i2c;
+ SemaphoreHandle_t I2CSemaphore;
};
#endif /* FRTOSI2C_HPP_ */
diff --git a/workspace/TS100/src/FRToSI2C.cpp b/workspace/TS100/src/FRToSI2C.cpp
index 061270f5..59b4d704 100644
--- a/workspace/TS100/src/FRToSI2C.cpp
+++ b/workspace/TS100/src/FRToSI2C.cpp
@@ -13,38 +13,81 @@ FRToSI2C::FRToSI2C(I2C_HandleTypeDef* i2chandle) {
}
void FRToSI2C::MasterTxCpltCallback() {
-
+ xSemaphoreGive(I2CSemaphore);
}
void FRToSI2C::MemRxCpltCallback() {
+ xSemaphoreGive(I2CSemaphore);
}
void FRToSI2C::MemTxCpltCallback() {
+ xSemaphoreGive(I2CSemaphore);
}
void FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
uint16_t MemAddSize, uint8_t* pData, uint16_t Size) {
- if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
- taskENTER_CRITICAL();
- HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
- 5000);
- if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
- taskEXIT_CRITICAL();
+ if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED
+ || RToSUP == false) {
+ //no RToS, run blocking code
+ HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
+ 5000);
+ } else {
+ //RToS is active, run threading
+ //Get the mutex so we can use the I2C port
+ //Wait up to 1 second for the mutex
+ if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 1000 ) == pdTRUE) {
+ HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData,
+ Size, 5000);
+ xSemaphoreGive(I2CSemaphore);
+
+ }
+
+ }
+
}
void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
uint16_t MemAddSize, uint8_t* pData, uint16_t Size) {
- if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
- taskENTER_CRITICAL();
- HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
- 5000);
- if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
- taskEXIT_CRITICAL();
+ if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED
+ || RToSUP == false) {
+ //no RToS, run blocking code
+ HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
+ 5000);
+ } else {
+ //RToS is active, run threading
+ //Get the mutex so we can use the I2C port
+ //Wait up to 1 second for the mutex
+ if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 1000 ) == pdTRUE) {
+ HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData,
+ Size, 5000);
+ xSemaphoreGive(I2CSemaphore);
+
+ }
+
+ }
+
+}
+
+void FRToSI2C::FRToSInit() {
+ I2CSemaphore = xSemaphoreCreateMutex();
+ xSemaphoreGive(I2CSemaphore);
+ RToSUP = true;
}
void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t* pData, uint16_t Size) {
- if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
- taskENTER_CRITICAL();
- HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000);
- if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
- taskEXIT_CRITICAL();
+ if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED
+ || RToSUP == false) {
+ //no RToS, run blocking code
+ HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000);
+ } else {
+ //RToS is active, run threading
+ //Get the mutex so we can use the I2C port
+ //Wait up to 1 second for the mutex
+ if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 1000 ) == pdTRUE) {
+ HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000);
+
+ xSemaphoreGive(I2CSemaphore);
+
+ }
+ }
+
}
diff --git a/workspace/TS100/src/OLED.cpp b/workspace/TS100/src/OLED.cpp
index 08381c26..ef67ad5a 100644
--- a/workspace/TS100/src/OLED.cpp
+++ b/workspace/TS100/src/OLED.cpp
@@ -60,6 +60,7 @@ OLED::OLED(FRToSI2C* i2cHandle) {
void OLED::initialize() {
HAL_Delay(5);
+
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
HAL_Delay(5);
//Send the setup settings
diff --git a/workspace/TS100/src/Setup.c b/workspace/TS100/src/Setup.c
index b1cb0036..37bf4e0f 100644
--- a/workspace/TS100/src/Setup.c
+++ b/workspace/TS100/src/Setup.c
@@ -77,7 +77,7 @@ void SystemClock_Config(void) {
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV16; //TIM 2,3,4,5,6,7,12,13,14
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; //64 mhz to soem peripherals and adc
+ RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; //64 mhz to some peripherals and adc
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp
index 8bc0cf91..0f24708d 100644
--- a/workspace/TS100/src/main.cpp
+++ b/workspace/TS100/src/main.cpp
@@ -44,6 +44,7 @@ int main(void) {
*/
HAL_Init();
Setup_HAL(); // Setup all the HAL objects
+ HAL_IWDG_Refresh(&hiwdg);
setTipPWM(0);
lcd.initialize(); // start up the LCD
lcd.setFont(0); // default to bigger font
@@ -641,6 +642,7 @@ static void gui_solderingMode() {
/* StartGUITask function */
void startGUITask(void const *argument) {
+ i2cDev.FRToSInit();
/*
* Main program states:
*
@@ -1085,3 +1087,16 @@ void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
+
+void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c) {
+}
+void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c) {
+ i2cDev.MasterTxCpltCallback();
+}
+void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c) {
+ i2cDev.MemTxCpltCallback();
+}
+
+void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c) {
+i2cDev.MemRxCpltCallback();
+}