semi-WIP Windows port

master
Clyne 4 years ago
parent cf20e4aceb
commit ae14f05fe3

2
.gitignore vendored

@ -6,3 +6,5 @@ build
eagle/*#*
gui/stmdspgui
doc/guide.odt
*.exe
*.dll

@ -1,19 +1,52 @@
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
RM = rm -f
else
RM = del
endif
CXX = g++-10
CXXFLAGS = --std=c++20 -ggdb -O0 \
-Wall -Wextra -pedantic \
-Wno-deprecated-copy \
-Iserial/include -IMETL/include -IMETL/dependencies/PEGTL/include \
$(shell wx-config --cxxflags)
-Wa,-mbig-obj
ifeq ($(UNAME), Linux)
CXXFLAGS += $(shell wx-config --cxxflags)
else
CXXFLAGS += -IC:\wx\include -DSTMDSP_WIN32
endif
ifeq ($(UNAME), Linux)
CXXFILES = serial/src/serial.cc \
serial/src/impl/unix.cc \
serial/src/impl/list_ports/list_ports_linux.cc \
$(wildcard *.cpp)
else
CXXFILES = serial/src/serial.cc \
serial/src/impl/win.cc \
serial/src/impl/list_ports/list_ports_win.cc \
$(wildcard *.cpp)
endif
OFILES = $(patsubst %.cc, %.o, $(patsubst %.cpp, %.o, $(CXXFILES)))
ifeq ($(UNAME), Linux)
LIBS = $(shell wx-config --libs) -lwx_gtk3u_stc-3.1
else
LIBS = -lSetupAPI \
-LC:\wx\lib\gcc810_x64_dll -lwxbase31u -lwxmsw31u_core -lwxmsw31u_stc
endif
OUTELF = stmdspgui
ifeq ($(UNAME), Linux)
CLEANFILES = $(OUTELF) $(OFILES)
else
CLEANFILES = $(subst /,\\,$(OUTELF)) $(subst /,\\,$(OFILES))
endif
all: $(OUTELF)
$(OUTELF): $(OFILES)
@ -30,5 +63,5 @@ $(OUTELF): $(OFILES)
clean:
@echo " CLEAN"
@rm -f $(OUTELF) $(OFILES)
@$(RM) $(CLEANFILES)

@ -30,6 +30,7 @@ namespace stmdsp
m_serial(file, 1000000/*230400*/, serial::Timeout::simpleTimeout(50))
{
if (m_serial.isOpen()) {
m_serial.flush();
m_serial.write("i");
if (auto id = m_serial.read(7); id.starts_with("stmdsp")) {
if (id.back() == 'h')

@ -24,7 +24,12 @@ namespace stmdsp
class scanner
{
private:
constexpr static const char *STMDSP_USB_ID = "USB VID:PID=0483:5740";
constexpr static const char *STMDSP_USB_ID =
#ifndef STMDSP_WIN32
"USB VID:PID=0483:5740";
#else
"USB\\VID_0483&PID_5740";
#endif
public:
std::list<std::string>& scan();

@ -12,6 +12,7 @@
#include "wxmain.hpp"
#include <wx/combobox.h>
#include <wx/dcbuffer.h>
#include <wx/dcclient.h>
#include <wx/dir.h>
#include <wx/filename.h>
@ -26,9 +27,12 @@
#include <wx/textdlg.h>
#include <array>
#include <sys/mman.h>
#include <vector>
#ifndef WIN32
#include <sys/mman.h>
#endif
#include "wxmain_devdata.h"
enum Id {
@ -81,7 +85,7 @@ MainFrame::MainFrame() :
m_compile_output = new wxTextCtrl(panelOutput, wxID_ANY,
wxEmptyString,
wxDefaultPosition, wxSize(620, 250),
wxTE_READONLY | wxTE_MULTILINE | wxHSCROLL);
wxTE_READONLY | wxTE_MULTILINE | wxHSCROLL | wxTE_RICH2);
m_measure_timer = new wxTimer(this, Id::MeasureTimer);
m_menu_bar = new wxMenuBar;
m_rate_select = new wxComboBox(panelToolbar, wxID_ANY,
@ -89,12 +93,17 @@ MainFrame::MainFrame() :
wxDefaultPosition, wxDefaultSize,
srateValues.size(), srateValues.data(),
wxCB_READONLY);
#ifndef WIN32
m_device_samples = reinterpret_cast<stmdsp::adcsample_t *>(::mmap(
nullptr, stmdsp::SAMPLES_MAX * sizeof(stmdsp::adcsample_t),
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0));
m_device_samples_input = reinterpret_cast<stmdsp::adcsample_t *>(::mmap(
nullptr, stmdsp::SAMPLES_MAX * sizeof(stmdsp::adcsample_t),
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0));
#else
m_device_samples = new stmdsp::adcsample_t[stmdsp::SAMPLES_MAX];
m_device_samples_input = new stmdsp::adcsample_t[stmdsp::SAMPLES_MAX];
#endif
m_menu_bar->Append(menuFile, "&File");
m_menu_bar->Append(menuRun, "&Run");
@ -102,7 +111,7 @@ MainFrame::MainFrame() :
SetMenuBar(m_menu_bar);
// Toolbar initialization
auto comp = new wxButton(panelToolbar, Id::MCodeCompile, "Compile");
auto comp = new wxButton(this, wxID_ANY, "Compile", {10, 10});
sizerToolbar->Add(comp, 0, wxLEFT, 4);
sizerToolbar->Add(m_rate_select, 0, wxLEFT, 12);
panelToolbar->SetSizer(sizerToolbar);
@ -122,7 +131,7 @@ MainFrame::MainFrame() :
// Main splitter init.
mainSplitter->SetSashGravity(0.5);
mainSplitter->SetMinimumPaneSize(20);
mainSplitter->SplitHorizontally(panelCode, panelOutput, 440);
mainSplitter->SplitHorizontally(panelCode, panelOutput, 100);
sizerMain->Add(mainSplitter, 1, wxEXPAND, 5);
sizerMain->SetSizeHints(this);
SetSizer(sizerMain);
@ -138,10 +147,9 @@ MainFrame::MainFrame() :
Bind(wxEVT_PAINT, &MainFrame::onPaint, this, wxID_ANY);
// Toolbar actions
Bind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY, comp);
Bind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, wxID_ANY, wxID_ANY, comp);
Bind(wxEVT_COMBOBOX, &MainFrame::onToolbarSampleRate, this, wxID_ANY, wxID_ANY, m_rate_select);
// File menu actions
Bind(wxEVT_MENU, &MainFrame::onFileNew, this, Id::MFileNew, wxID_ANY, menuFile->Append(MFileNew, "&New"));
Bind(wxEVT_MENU, &MainFrame::onFileOpen, this, Id::MFileOpen, wxID_ANY, menuFile->Append(MFileOpen, "&Open"));
@ -169,9 +177,9 @@ MainFrame::MainFrame() :
// Code menu actions
Bind(wxEVT_MENU, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY, menuCode->Append(MCodeCompile, "&Compile code"));
Bind(wxEVT_MENU, &MainFrame::onCodeDisassemble, this, Id::MCodeDisassemble, wxID_ANY, menuCode->Append(MCodeDisassemble, "Show &Disassembly"));
menuCode->AppendSeparator();
updateMenuOptions();
comp->Raise();
}
// Closes the window
@ -187,7 +195,7 @@ void MainFrame::onCloseEvent(wxCloseEvent& event)
delete m_device;
Unbind(wxEVT_COMBOBOX, &MainFrame::onToolbarSampleRate, this, wxID_ANY, wxID_ANY);
Unbind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY);
Unbind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, wxID_ANY, wxID_ANY);
event.Skip();
}
@ -203,9 +211,10 @@ void MainFrame::onMeasureTimer(wxTimerEvent&)
if (m_conv_result_log) {
for (auto& s : samples) {
auto str = std::to_string(s);
auto str = std::to_string(s) + ',';
m_conv_result_log->Write(str.c_str(), str.size());
}
m_conv_result_log->Write("\n", 1);
}
if (m_run_draw_samples->IsChecked()) {
samples = m_device->continuous_read_input();
@ -250,7 +259,7 @@ void MainFrame::onPaint(wxPaintEvent&)
this->GetSize().GetHeight() - py - 60
};
auto *dc = new wxPaintDC(this);
auto *dc = new wxBufferedPaintDC(this);
dc->SetBrush(*wxBLACK_BRUSH);
dc->SetPen(*wxBLACK_PEN);
dc->DrawRectangle(rect);
@ -321,38 +330,56 @@ void MainFrame::prepareEditor()
wxString MainFrame::compileEditorCode()
{
if (m_device == nullptr) {
m_status_bar->SetStatusText("Need device connected to compile.");
return "";
stmdsp::platform platform;
if (m_device != nullptr) {
platform = m_device->get_platform();
} else {
m_status_bar->SetStatusText("Assuming L4 platform...");
platform = stmdsp::platform::L4;
}
if (m_temp_file_name.IsEmpty())
m_temp_file_name = wxFileName::CreateTempFileName("stmdspgui");
wxFile file (m_temp_file_name, wxFile::write);
wxString file_text (m_device->get_platform() == stmdsp::platform::L4 ? file_header_l4
wxString file_text (platform == stmdsp::platform::L4 ? file_header_l4
: file_header_h7);
file_text.Replace("$0", std::to_string(m_device ? m_device->get_buffer_size()
: stmdsp::SAMPLES_MAX));
file.Write(wxString(file_text) + m_text_editor->GetText());
file.Close();
wxFile makefile (m_temp_file_name + ".sh", wxFile::write);
wxString make_text (m_device->get_platform() == stmdsp::platform::L4 ? makefile_text_l4
constexpr const char *script_ext =
#ifndef STMDSP_WIN32
".sh";
#else
".bat";
#endif
wxFile makefile (m_temp_file_name + script_ext, wxFile::write);
wxString make_text (platform == stmdsp::platform::L4 ? makefile_text_l4
: makefile_text_h7);
make_text.Replace("$0", m_temp_file_name);
makefile.Write(make_text);
makefile.Close();
wxString make_output = m_temp_file_name + ".sh.log";
wxString make_command = m_temp_file_name + ".sh > " + make_output + " 2>&1";
wxString make_output = m_temp_file_name + script_ext + ".log";
wxString make_command = m_temp_file_name + script_ext + " > " +
make_output + " 2>&1";
system(wxString("chmod +x ") + m_temp_file_name + ".sh");
#ifndef STMDSP_WIN32
system(wxString("chmod +x ") + m_temp_file_name + script_ext);
#endif
int result = system(make_command.ToAscii());
m_compile_output->LoadFile(make_output);
wxFile result_file (make_output);
wxString result_text;
result_file.ReadAll(&result_text);
result_file.Close();
m_compile_output->Clear();
m_compile_output->WriteText(result_text);
wxRemoveFile(m_temp_file_name);
wxRemoveFile(m_temp_file_name + ".sh");
wxRemoveFile(m_temp_file_name + script_ext);
wxRemoveFile(make_output);
if (result == 0) {
@ -380,19 +407,21 @@ void MainFrame::onCodeDisassemble(wxCommandEvent&)
" > " + output + " 2>&1";
if (system(command.ToAscii()) == 0) {
m_compile_output->LoadFile(output);
wxFile result_file (output);
wxString result_text;
result_file.ReadAll(&result_text);
result_file.Close();
m_compile_output->Clear();
m_compile_output->WriteText(result_text);
wxRemoveFile(output);
m_status_bar->SetStatusText(wxString::Format(wxT("Done. Line count: %u."),
m_compile_output->GetNumberOfLines()));
} else {
m_compile_output->ChangeValue("");
m_status_bar->SetStatusText("Failed to load disassembly.");
}
} else {
m_compile_output->ChangeValue("");
m_status_bar->SetStatusText("Need to compile code before analyzing.");
}
wxRemoveFile(output);
}
wxMenu *MainFrame::loadTemplates()

@ -17,20 +17,25 @@ const std::array<unsigned int, 6> srateNums {
96000
};
#ifdef WIN32
#ifdef STMDSP_WIN32
#define NEWLINE "\r\n"
#define COPY "copy"
#else
#define NEWLINE "\n"
#define COPY "cp"
#endif
// $0 = temp file name
const char *makefile_text_h7 =
#ifdef STMDSP_WIN32
"echo off" NEWLINE
#endif
"arm-none-eabi-g++ -x c++ -Os -std=c++20 -fno-exceptions -fno-rtti "
"-mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 -mtune=cortex-m7 "
"-nostartfiles "
"-Wl,-Ttext-segment=0x00000000 -Wl,-zmax-page-size=512 -Wl,-eprocess_data_entry "
"$0 -o $0.o" NEWLINE
"cp $0.o $0.orig.o" NEWLINE
COPY " $0.o $0.orig.o" NEWLINE
"arm-none-eabi-strip -s -S --strip-unneeded $0.o" NEWLINE
"arm-none-eabi-objcopy --remove-section .ARM.attributes "
"--remove-section .comment "
@ -38,12 +43,15 @@ const char *makefile_text_h7 =
"$0.o" NEWLINE
"arm-none-eabi-size $0.o" NEWLINE;
const char *makefile_text_l4 =
#ifdef STMDSP_WIN32
"echo off" NEWLINE
#endif
"arm-none-eabi-g++ -x c++ -Os -std=c++20 -fno-exceptions -fno-rtti "
"-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 "
"-nostartfiles "
"-Wl,-Ttext-segment=0x10000000 -Wl,-zmax-page-size=512 -Wl,-eprocess_data_entry "
"$0 -o $0.o" NEWLINE
"cp $0.o $0.orig.o" NEWLINE
COPY " $0.o $0.orig.o" NEWLINE
"arm-none-eabi-strip -s -S --strip-unneeded $0.o" NEWLINE
"arm-none-eabi-objcopy --remove-section .ARM.attributes "
"--remove-section .comment "

Loading…
Cancel
Save