diff --git a/Core/Src/isrs.cpp b/Core/Src/isrs.cpp index 90e0079..6f5d653 100644 --- a/Core/Src/isrs.cpp +++ b/Core/Src/isrs.cpp @@ -8,6 +8,10 @@ #include "stm32f7xx_hal.h" #include "main.h" #include "board/buttonscontroller.h" +#include "app/factory.h" + +uint16_t adcValuesBuffer[ADC_VALUES_BUFFER_SIZE]; +int ADCBufferIndex = 0; extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) @@ -26,8 +30,10 @@ extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) } extern "C" void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef * hadc) { - HAL_GPIO_TogglePin(OUT1_GPIO_Port, OUT1_Pin); - volatile uint32_t value = HAL_ADC_GetValue(hadc); + //HAL_GPIO_TogglePin(OUT1_GPIO_Port, OUT1_Pin); + adcValuesBuffer[ADCBufferIndex] = HAL_ADC_GetValue(hadc); + ADCBufferIndex++; + if(ADCBufferIndex == ADC_VALUES_BUFFER_SIZE) ADCBufferIndex = 0; } diff --git a/Core/Src/main.c b/Core/Src/main.c index 50c5fff..3a9209f 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -18,12 +18,14 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" +#include "app_touchgfx.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "xf/xf.h" #include "xf/port/port-functions.h" +#include "app/factory.h" /* USER CODE END Includes */ @@ -34,6 +36,22 @@ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ + +#define REFRESH_COUNT 1835 + +#define SDRAM_TIMEOUT ((uint32_t)0xFFFF) +#define SDRAM_MODEREG_BURST_LENGTH_1 ((uint16_t)0x0000) +#define SDRAM_MODEREG_BURST_LENGTH_2 ((uint16_t)0x0001) +#define SDRAM_MODEREG_BURST_LENGTH_4 ((uint16_t)0x0002) +#define SDRAM_MODEREG_BURST_LENGTH_8 ((uint16_t)0x0004) +#define SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL ((uint16_t)0x0000) +#define SDRAM_MODEREG_BURST_TYPE_INTERLEAVED ((uint16_t)0x0008) +#define SDRAM_MODEREG_CAS_LATENCY_2 ((uint16_t)0x0020) +#define SDRAM_MODEREG_CAS_LATENCY_3 ((uint16_t)0x0030) +#define SDRAM_MODEREG_OPERATING_MODE_STANDARD ((uint16_t)0x0000) +#define SDRAM_MODEREG_WRITEBURST_MODE_PROGRAMMED ((uint16_t)0x0000) +#define SDRAM_MODEREG_WRITEBURST_MODE_SINGLE ((uint16_t)0x0200) + /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ @@ -67,7 +85,7 @@ UART_HandleTypeDef huart1; SDRAM_HandleTypeDef hsdram1; /* USER CODE BEGIN PV */ - +static FMC_SDRAM_CommandTypeDef Command; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -87,6 +105,7 @@ static void MX_TIM3_Init(void); static void MX_TIM5_Init(void); static void MX_TIM8_Init(void); static void MX_USART1_UART_Init(void); +void TouchGFX_Task(void *argument); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ @@ -142,8 +161,15 @@ int main(void) MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ - HAL_TIM_OC_Start_IT(&htim1, TIM_CHANNEL_1); - HAL_ADC_Start_IT(&hadc3); + //HAL_TIM_OC_Start_IT(&htim1, TIM_CHANNEL_1); + //HAL_ADC_Start_IT(&hadc3); + + MX_TouchGFX_Init(); + + XF_initialize(10); + Factory_initialize(); + Factory_build(); + XF_exec(); /* USER CODE END 2 */ @@ -151,8 +177,6 @@ int main(void) /* USER CODE BEGIN WHILE */ while (1) { - //HAL_Delay(2000); - /* USER CODE END WHILE */ @@ -939,6 +963,61 @@ static void MX_FMC_Init(void) /* USER CODE BEGIN FMC_Init 2 */ + __IO uint32_t tmpmrd = 0; + + /* Step 1: Configure a clock configuration enable command */ + Command.CommandMode = FMC_SDRAM_CMD_CLK_ENABLE; + Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1; + Command.AutoRefreshNumber = 1; + Command.ModeRegisterDefinition = 0; + + /* Send the command */ + HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT); + + /* Step 2: Insert 100 us minimum delay */ + /* Inserted delay is equal to 1 ms due to systick time base unit (ms) */ + HAL_Delay(1); + + /* Step 3: Configure a PALL (precharge all) command */ + Command.CommandMode = FMC_SDRAM_CMD_PALL; + Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1; + Command.AutoRefreshNumber = 1; + Command.ModeRegisterDefinition = 0; + + /* Send the command */ + HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT); + + /* Step 4: Configure an Auto Refresh command */ + Command.CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE; + Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1; + Command.AutoRefreshNumber = 8; + Command.ModeRegisterDefinition = 0; + + /* Send the command */ + HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT); + + /* Step 5: Program the external memory mode register */ + tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_1 | \ + SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL | \ + SDRAM_MODEREG_CAS_LATENCY_3 | \ + SDRAM_MODEREG_OPERATING_MODE_STANDARD | \ + SDRAM_MODEREG_WRITEBURST_MODE_SINGLE; + + Command.CommandMode = FMC_SDRAM_CMD_LOAD_MODE; + Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1; + Command.AutoRefreshNumber = 1; + Command.ModeRegisterDefinition = tmpmrd; + + /* Send the command */ + HAL_SDRAM_SendCommand(&hsdram1, &Command, SDRAM_TIMEOUT); + + /* Step 6: Set the refresh rate counter */ + /* Set the device refresh rate */ + HAL_SDRAM_ProgramRefreshRate(&hsdram1, REFRESH_COUNT); + + //Deactivate speculative/cache access to first FMC Bank to save FMC bandwidth + FMC_Bank1->BTCR[0] = 0x000030D2; + /* USER CODE END FMC_Init 2 */ } diff --git a/src/app/factory.cpp b/src/app/factory.cpp index c5b891f..966e591 100644 --- a/src/app/factory.cpp +++ b/src/app/factory.cpp @@ -6,6 +6,9 @@ extern "C" TIM_HandleTypeDef htim1; // Defined in main.c extern "C" ADC_HandleTypeDef hadc3; // Defined in main.c +extern "C" uint16_t adcValuesBuffer[ADC_VALUES_BUFFER_SIZE]; +extern "C" int ADCBufferIndex; + oscilloscope::Controller Factory::_oscilloscopeController; oscilloscope::Gui Factory::_gui; external::FrequencyGenerator Factory::_fgen; @@ -34,8 +37,7 @@ void Factory::initialize() Trace::out("---------------------------------------------"); Trace::out("Initializing..."); - // TODO: Uncomment code line below in order to call OscilloscopeController's initialize() method -// getOscilloscopeController().initialize(getGui(), adcValuesBuffer, ADC_VALUES_BUFFER_SIZE); + getOscilloscopeController().initialize(getGui(), adcValuesBuffer, ADC_VALUES_BUFFER_SIZE); getFrequencyGenerator().initialize(); getFreqGenController().initialize(getGui()); #if (TOUCHGFX_BAREMETAL != 0) diff --git a/src/app/factory.h b/src/app/factory.h index ff443bf..9680992 100644 --- a/src/app/factory.h +++ b/src/app/factory.h @@ -18,6 +18,8 @@ #include "board/buttonscontroller.h" using external::FrequencyGenerator; +#define ADC_VALUES_BUFFER_SIZE 8000 + /** * @brief Factory creating all objects/components and relations between them. */ diff --git a/src/app/oscilloscopecontroller.cpp b/src/app/oscilloscopecontroller.cpp index 120020b..5d7512d 100644 --- a/src/app/oscilloscopecontroller.cpp +++ b/src/app/oscilloscopecontroller.cpp @@ -108,9 +108,20 @@ void Controller::onCheckBoxTriggerCheckState(bool checked) GEN(evCheckBoxTrigger(checked, CHECK_BOX_TRIGGER_ID)); } -void Controller::doShowAnalogSignal() -{ - // TODO: Call gui().drawGraphPoints() with the appropriate data. +void Controller::doShowAnalogSignal() { + + /* + * 460px for 8 div + * fs = 100kHz => 100 samples/ms + * 500 us/div => 400 samples => scale = 400/460 = 0,870 + * 1 ms/div => 800 samples => scale = 800/460 = 1,739 + * 2 ms/div => 1600 samples => scale = 1600/460 = 3,478 + * 5 ms/div => 4000 samples => scale = 4000/460 = 8,696 + * 10 ms/div => 8000 samples => scale = 8000/460 = 17,391 + */ + static float scales[7] = {0.87,0.87,1.739,3.478,8.696,17.391,17.391}; + float scale = scales[this->_tdivValue]; + gui().drawGraphPoints(_adcValuesBuffer, _adcValuesBufferSize, scale); } void Controller::doButtonTimePlusPressed()