]> code.bitgloo.com Git - clyne/stmdsp.git/commitdiff
firmware can port to L432KC; gui: edit buffer size
authorClyne Sullivan <clyne@bitgloo.com>
Wed, 21 Oct 2020 00:14:08 +0000 (20:14 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Wed, 21 Oct 2020 00:14:08 +0000 (20:14 -0400)
Makefile
cfg/mcuconf.h
gui/stmdsp.cpp
gui/stmdsp.hpp
gui/wxmain.cpp
gui/wxmain.hpp
source/adc.cpp
source/main.cpp

index 7cfc8fe1de6011ded63fac4d9858592b2ee161db..3b0591781fc6c8674a37e7e3775068390a64cb0b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -55,13 +55,13 @@ endif
 # Stack size to be allocated to the Cortex-M process stack. This stack is\r
 # the stack used by the main() thread.\r
 ifeq ($(USE_PROCESS_STACKSIZE),)\r
-  USE_PROCESS_STACKSIZE = 8192\r
+  USE_PROCESS_STACKSIZE = 4096\r
 endif\r
 \r
 # Stack size to the allocated to the Cortex-M main/exceptions stack. This\r
 # stack is used for processing interrupts and exceptions.\r
 ifeq ($(USE_EXCEPTIONS_STACKSIZE),)\r
-  USE_EXCEPTIONS_STACKSIZE = 0x400\r
+  USE_EXCEPTIONS_STACKSIZE = 1024\r
 endif\r
 \r
 # Enables the use of FPU (no, softfp, hard).\r
@@ -102,6 +102,8 @@ include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32l4xx.m
 include $(CHIBIOS)/os/hal/hal.mk\r
 include $(CHIBIOS)/os/hal/ports/STM32/STM32L4xx/platform.mk\r
 include $(CHIBIOS)/os/hal/boards/ST_STM32L476_DISCOVERY/board.mk\r
+#include $(CHIBIOS)/os/hal/boards/ST_NUCLEO32_L432KC/board.mk\r
+#include $(CHIBIOS)/os/hal/ports/STM32/STM32L4xx/platform_l432.mk\r
 include $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk\r
 # RTOS files (optional).\r
 include $(CHIBIOS)/os/rt/rt.mk\r
@@ -115,6 +117,7 @@ include $(CHIBIOS)/tools/mk/autobuild.mk
 \r
 # Define linker script file here.\r
 LDSCRIPT= $(STARTUPLD)/STM32L476xG.ld\r
+#LDSCRIPT= $(STARTUPLD)/STM32L432xC.ld\r
 \r
 # C sources that can be compiled in ARM or THUMB mode depending on the global\r
 # setting.\r
index 8b49f7a4b22bb5233b08490863339c3e40ee1edc..929e04990be018aae86a5ab0931d4dc9060eebd1 100644 (file)
@@ -33,7 +33,7 @@
 \r
 #define STM32L4xx_MCUCONF\r
 #define STM32L476_MCUCONF\r
-#define STM32L486_MCUCONF\r
+//#define STM32L432_MCUCONF\r
 \r
 /*\r
  * HAL driver system settings.\r
 #define STM32_ADC_DUAL_MODE                 FALSE\r
 #define STM32_ADC_COMPACT_SAMPLES           FALSE\r
 #define STM32_ADC_USE_ADC1                  TRUE\r
-#define STM32_ADC_USE_ADC2                  TRUE\r
-#define STM32_ADC_USE_ADC3                  TRUE\r
+#define STM32_ADC_USE_ADC2                  FALSE\r
+#define STM32_ADC_USE_ADC3                  FALSE \r
 #define STM32_ADC_ADC1_DMA_STREAM           STM32_DMA_STREAM_ID(1, 1)\r
 #define STM32_ADC_ADC2_DMA_STREAM           STM32_DMA_STREAM_ID(1, 2)\r
 #define STM32_ADC_ADC3_DMA_STREAM           STM32_DMA_STREAM_ID(1, 3)\r
 #define STM32_GPT_USE_TIM1                  FALSE\r
 #define STM32_GPT_USE_TIM2                  FALSE\r
 #define STM32_GPT_USE_TIM3                  FALSE\r
-#define STM32_GPT_USE_TIM4                  TRUE\r
+#define STM32_GPT_USE_TIM4                  FALSE\r
 #define STM32_GPT_USE_TIM5                  FALSE\r
 #define STM32_GPT_USE_TIM6                  TRUE\r
-#define STM32_GPT_USE_TIM7                  FALSE\r
+#define STM32_GPT_USE_TIM7                  TRUE\r
 #define STM32_GPT_USE_TIM8                  FALSE\r
 #define STM32_GPT_USE_TIM15                 FALSE\r
 #define STM32_GPT_USE_TIM16                 FALSE\r
 /*\r
  * USB driver system settings.\r
  */\r
+#ifdef STM32L476_MCUCONF\r
 #define STM32_USB_USE_OTG1                  TRUE\r
 #define STM32_USB_OTG1_IRQ_PRIORITY         14\r
 #define STM32_USB_OTG1_RX_FIFO_SIZE         512\r
+#else\r
+#define STM32_USB_USE_USB1                  TRUE\r
+#define STM32_USB_LOW_POWER_ON_SUSPEND      FALSE\r
+#define STM32_USB_USB1_HP_IRQ_PRIORITY      13\r
+#define STM32_USB_USB1_LP_IRQ_PRIORITY      14\r
+#endif // STM32L476_MCUCONF\r
 \r
 /*\r
  * WDG driver system settings.\r
index 87b608d9570bbb74e27330a5a7f6d1716a901ce7..633c61ac3845754d8835484582dfcb4155dbf50c 100644 (file)
@@ -41,6 +41,17 @@ namespace stmdsp
         }
     }*/
 
+    void device::continuous_set_buffer_size(unsigned int size) {
+        if (connected()) {
+            uint8_t request[3] = {
+                'B',
+                static_cast<uint8_t>(size),
+                static_cast<uint8_t>(size >> 8)
+            };
+            m_serial.write(request, 3);
+        }
+    }
+
     void device::continuous_start() {
         if (connected())
             m_serial.write("R");
index a9b8b7e3b3ef69ab025b906c5d489f60bb51b5a8..46113bf900b1e61d4f3fc48c49f95682620aacf0 100644 (file)
@@ -8,6 +8,8 @@
 
 namespace stmdsp
 {
+    constexpr unsigned int SAMPLES_MAX = 4000;
+
     class scanner
     {
     private:
index aa57066156a6e5b702911968b4ecf0ff0094accd..c9e8b3d694d17bd2d82c223700e94fad8ee92e26 100644 (file)
@@ -28,6 +28,7 @@ enum Id {
     MRunMeasure,
     MRunUpload,
     MRunUnload,
+    MRunEditBSize,
     MRunGenUpload,
     MRunGenStart,
     MCodeCompile,
@@ -103,6 +104,8 @@ MainFrame::MainFrame() : wxFrame(nullptr, wxID_ANY, "stmdspgui", wxPoint(50, 50)
          menuRun->Append(MRunUpload, "&Upload code"));
     Bind(wxEVT_MENU, &MainFrame::onRunUnload, this, Id::MRunUnload, wxID_ANY,
          menuRun->Append(MRunUnload, "U&nload code"));
+    Bind(wxEVT_MENU, &MainFrame::onRunEditBSize, this, Id::MRunEditBSize, wxID_ANY,
+         menuRun->Append(MRunEditBSize, "Set &buffer size..."));
 
     menuRun->AppendSeparator();
     Bind(wxEVT_MENU, &MainFrame::onRunGenUpload, this, Id::MRunGenUpload, wxID_ANY,
@@ -409,10 +412,38 @@ void MainFrame::onRunStart(wxCommandEvent& ce)
     }
 }
 
+void MainFrame::onRunEditBSize([[maybe_unused]] wxCommandEvent&)
+{
+    if (m_device != nullptr && m_device->connected()) {
+        wxTextEntryDialog dialog (this, "Enter new buffer size (100-4000)", "Set Buffer Size");
+        if (dialog.ShowModal() == wxID_OK) {
+            if (wxString value = dialog.GetValue(); !value.IsEmpty()) {
+                if (unsigned long n; value.ToULong(&n)) {
+                    if (n >= 100 && n <= stmdsp::SAMPLES_MAX) {
+                        m_device->continuous_set_buffer_size(n);
+                    } else {
+                        m_status_bar->SetStatusText("Error: Invalid buffer size.");
+                    }
+                } else {
+                    m_status_bar->SetStatusText("Error: Invalid buffer size.");
+                }
+            } else {
+                m_status_bar->SetStatusText("Ready.");
+            }
+        } else {
+            m_status_bar->SetStatusText("Ready.");
+        }
+    } else {
+        wxMessageBox("No device connected!", "Run", wxICON_WARNING);
+        m_status_bar->SetStatusText("Please connect.");
+    }
+}
+
 void MainFrame::onRunGenUpload([[maybe_unused]] wxCommandEvent&)
 {
     if (m_device != nullptr && m_device->connected()) {
-        wxTextEntryDialog dialog (this, "Enter generator values", "Hey");
+        wxTextEntryDialog dialog (this, "Enter generator values below. Values must be whole numbers "
+                                        "between zero and 4095.", "Enter Generator Values");
         if (dialog.ShowModal() == wxID_OK) {
             if (wxString values = dialog.GetValue(); !values.IsEmpty()) {
                 std::vector<stmdsp::dacsample_t> samples;
@@ -436,8 +467,17 @@ void MainFrame::onRunGenUpload([[maybe_unused]] wxCommandEvent&)
                     }
                 }
 
-                m_device->siggen_upload(&samples[0], samples.size());
+                if (samples.size() <= stmdsp::SAMPLES_MAX) {
+                    m_device->siggen_upload(&samples[0], samples.size());
+                    m_status_bar->SetStatusText("Generator ready.");
+                } else {
+                    m_status_bar->SetStatusText("Error: Too many samples.");
+                }
+            } else {
+                m_status_bar->SetStatusText("Error: No samples given.");
             }
+        } else {
+            m_status_bar->SetStatusText("Ready.");
         }
     } else {
         wxMessageBox("No device connected!", "Run", wxICON_WARNING);
@@ -500,7 +540,7 @@ void MainFrame::onRunCompile([[maybe_unused]] wxCommandEvent&)
 void MainFrame::onCodeDisassemble([[maybe_unused]] wxCommandEvent&)
 {
     auto output = m_temp_file_name + ".asm.log";
-    wxString command = wxString("arm-none-eabi-objdump -d ") + m_temp_file_name + ".orig.o"
+    wxString command = wxString("arm-none-eabi-objdump -d --no-show-raw-insn ") + m_temp_file_name + ".orig.o"
                                 " > " + output + " 2>&1";
 
     if (system(command.ToAscii()) == 0) {
index 0da0b79ea2feaf3dcd4969276915cf81951d6be6..60c3ee11a4ba1ab299c5c65c9037eb85a5eab79f 100644 (file)
@@ -36,6 +36,7 @@ public:
     void onRunStart(wxCommandEvent&);
     void onRunUpload(wxCommandEvent&);
     void onRunUnload(wxCommandEvent&);
+    void onRunEditBSize(wxCommandEvent&);
     void onRunGenUpload(wxCommandEvent&);
     void onRunGenStart(wxCommandEvent&);
 
index 6c1af7b2ccc01b90c26c7cfe78dcc3c63a6c429e..84620a20179a6f3ac46d7c31c6671ad8f992cc83 100644 (file)
@@ -12,7 +12,7 @@
 #include "adc.hpp"
 
 constexpr static const auto adcd = &ADCD1;
-constexpr static const auto gptd = &GPTD4;
+constexpr static const auto gptd = &GPTD7;
 
 constexpr static const ADCConfig adc_config = {
     .difsel = 0
index 63bd66b2de9127e8ad1dc33b19256d4736034868..7a55b6cb520e753d08ee679231f79fd05d3d55b1 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <array>
 
-constexpr unsigned int MAX_ELF_FILE_SIZE = 12 * 1024;
+constexpr unsigned int MAX_ELF_FILE_SIZE = 8 * 1024;
 constexpr unsigned int MAX_ERROR_QUEUE_SIZE = 8;
 constexpr unsigned int MAX_SAMPLE_BUFFER_SIZE = 8000;
 
@@ -118,8 +118,8 @@ int main()
 static unsigned int dac_sample_count = MAX_SAMPLE_BUFFER_SIZE;
 static unsigned int dac2_sample_count = MAX_SAMPLE_BUFFER_SIZE;
 static unsigned int adc_sample_count = MAX_SAMPLE_BUFFER_SIZE;
-static bool adc_preloaded = false;
-static bool dac_preloaded = false;
+//static bool adc_preloaded = false;
+//static bool dac_preloaded = false;
 
 void main_loop()
 {
@@ -138,8 +138,6 @@ void main_loop()
                     usbserial::read(&adc_samples[0], adc_sample_count * sizeof(adcsample_t));
                     break;
 
-                case 'b':
-                    break;
                 case 'B':
                     if (run_status == RunStatus::Idle) {
                         if (usbserial::read(&cmd[1], 2) == 2) {
@@ -225,9 +223,9 @@ void main_loop()
                     if (run_status == RunStatus::Idle) {
                         run_status = RunStatus::Running;
                         dac_samples.fill(0);
-                        if (!adc_preloaded)
+                        //if (!adc_preloaded)
                             adc::read_start(signal_operate_measure, &adc_samples[0], adc_sample_count);
-                        if (!dac_preloaded)
+                        //if (!dac_preloaded)
                             dac::write_start(0, &dac_samples[0], dac_sample_count);
                     } else {
                         error_queue_add(Error::NotIdle);
@@ -246,30 +244,30 @@ void main_loop()
                     if (run_status == RunStatus::Idle) {
                         run_status = RunStatus::Running;
                         dac_samples.fill(0);
-                        if (!adc_preloaded)
+                        //if (!adc_preloaded)
                             adc::read_start(signal_operate, &adc_samples[0], adc_sample_count);
-                        if (!dac_preloaded)
+                        //if (!dac_preloaded)
                             dac::write_start(0, &dac_samples[0], dac_sample_count);
                     } else {
                         error_queue_add(Error::NotIdle);
                     }
                     break;
 
-                case 'r':
-                    if (usbserial::read(&cmd[1], 1) == 1) {
-                        adc_preloaded = cmd[1] & (1 << 0);
-                        dac_preloaded = cmd[1] & (1 << 1);
-                    } else {
-                        error_queue_add(Error::BadParamSize);
-                    }
-                    break;
+                //case 'r':
+                //    if (usbserial::read(&cmd[1], 1) == 1) {
+                //        adc_preloaded = cmd[1] & (1 << 0);
+                //        dac_preloaded = cmd[1] & (1 << 1);
+                //    } else {
+                //        error_queue_add(Error::BadParamSize);
+                //    }
+                //    break;
 
                 // 'S' - Stops the continuous sampling/conversion.
                 case 'S':
                     if (run_status == RunStatus::Running) {
-                        if (!dac_preloaded)
+                        //if (!dac_preloaded)
                             dac::write_stop(0);
-                        if (!adc_preloaded)
+                        //if (!adc_preloaded)
                             adc::read_stop();
                         run_status = RunStatus::Idle;
                     }
@@ -295,9 +293,9 @@ void main_loop()
 void conversion_abort()
 {
     elf_entry = nullptr;
-    if (!dac_preloaded)
+    //if (!dac_preloaded)
         dac::write_stop(0);
-    if (!adc_preloaded)
+    //if (!adc_preloaded)
         adc::read_stop();
     error_queue_add(Error::ConversionAborted);
 }