Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fw #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Fw #7

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
/sw/InductorTester/obj/Debug
/sw/InductorTester/*.suo
/fw/f4discovery/bin/*.map
/sw/InductorTester/bin
/sw/InductorTester/TestResults
/sw/InductorTester/obj
4 changes: 2 additions & 2 deletions fw/f4discovery/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ clean:

%.flash: %.elf
@$(PRINTF) " GDB $< (flash)\n"
$(Q)$(GDB) --batch -ex 'target extended-remote COM3' \
$(Q)$(GDB) --batch -ex 'target extended-remote COM4' \
-x $(OPENCM3_DIR)scripts/black_magic_probe_flash.scr $<

%.gdb: %.elf
@$(PRINTF) " GDB $< (gdb)\n"
$(Q)$(GDB) -ex 'target extended-remote COM3' \
$(Q)$(GDB) -ex 'target extended-remote COM4' \
-x $(OPENCM3_DIR)scripts/black_magic_probe_flash.scr $<

###############################################################################
Expand Down
8 changes: 8 additions & 0 deletions fw/f4discovery/include/dac.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef DAC_H_INCLUDED
#define DAC_H_INCLUDED
#include <libopencm3/stm32/dac.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h>
void dac_init(void);
void set_napeti(uint16_t napeti);
#endif // DAC_H_INCLUDED
24 changes: 24 additions & 0 deletions fw/f4discovery/include/protokol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef PROTOKOL_H_INCLUDED
#define PROTOKOL_H_INCLUDED


#include <libopencm3/cm3/scb.h>
#include <libopencm3/stm32/timer.h>

#include "pwm.h"
#include "dac.h"

struct Param_Mer
{
uint8_t set_param;
uint8_t start_mer;
uint16_t Napeti;
uint16_t Cas_Nas;
uint32_t default_pwm[4];
};

void protokol(char *buf);
void set_mer(void);
void init_protokol(void);

#endif // PROTOKOL_H_INCLUDED
207 changes: 207 additions & 0 deletions fw/f4discovery/include/usb_vilem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
#ifndef usb_vilem_154763
#define usb_vilem_154763

#include <stdlib.h>

#include <libopencm3/stm32/f4/rcc.h>

#include <libopencm3/stm32/f4/gpio.h>

#include <libopencm3/usb/usbd.h>

#include <libopencm3/usb/cdc.h>

#include <libopencm3/cm3/scb.h>

static const struct usb_device_descriptor dev = {
.bLength = USB_DT_DEVICE_SIZE,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = USB_CLASS_CDC,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bMaxPacketSize0 = 64,
.idVendor = 0x0483,
.idProduct = 0x5740,
.bcdDevice = 0x0200,
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 3,
.bNumConfigurations = 1,

};




// * This notification endpoint isn't implemented. According to CDC spec it's
// * optional, but its absence causes a NULL pointer dereference in the
// * Linux cdc_acm driver.
//

static const struct usb_endpoint_descriptor comm_endp[] = {{
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x83,
.bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
.wMaxPacketSize = 16,
.bInterval = 255,
}};


static const struct usb_endpoint_descriptor data_endp[] =
{
{
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x01,
.bmAttributes = USB_ENDPOINT_ATTR_BULK,
.wMaxPacketSize = 64,
.bInterval = 1,
},

{
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x82,
.bmAttributes = USB_ENDPOINT_ATTR_BULK,
.wMaxPacketSize = 64,
.bInterval = 1,
}
};



static const struct
{
struct usb_cdc_header_descriptor header;
struct usb_cdc_call_management_descriptor call_mgmt;
struct usb_cdc_acm_descriptor acm;
struct usb_cdc_union_descriptor cdc_union;
}
__attribute__((packed)) cdcacm_functional_descriptors =
{

.header =
{
.bFunctionLength = sizeof(struct usb_cdc_header_descriptor),
.bDescriptorType = CS_INTERFACE,
.bDescriptorSubtype = USB_CDC_TYPE_HEADER,
.bcdCDC = 0x0110,
},

.call_mgmt =
{
.bFunctionLength =
sizeof(struct usb_cdc_call_management_descriptor),
.bDescriptorType = CS_INTERFACE,
.bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT,
.bmCapabilities = 0,
.bDataInterface = 1,
},

.acm =
{
.bFunctionLength = sizeof(struct usb_cdc_acm_descriptor),
.bDescriptorType = CS_INTERFACE,
.bDescriptorSubtype = USB_CDC_TYPE_ACM,
.bmCapabilities = 0,
},

.cdc_union =
{
.bFunctionLength = sizeof(struct usb_cdc_union_descriptor),
.bDescriptorType = CS_INTERFACE,
.bDescriptorSubtype = USB_CDC_TYPE_UNION,
.bControlInterface = 0,
.bSubordinateInterface0 = 1,
}

};



static const struct usb_interface_descriptor comm_iface[] =
{
{
.bLength = USB_DT_INTERFACE_SIZE,
.bDescriptorType = USB_DT_INTERFACE,
.bInterfaceNumber = 0,
.bAlternateSetting = 0,
.bNumEndpoints = 1,
.bInterfaceClass = USB_CLASS_CDC,
.bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
.bInterfaceProtocol = USB_CDC_PROTOCOL_AT,
.iInterface = 0,

.endpoint = comm_endp,

.extra = &cdcacm_functional_descriptors,
.extralen = sizeof(cdcacm_functional_descriptors)
}};



static const struct usb_interface_descriptor data_iface[] =
{{
.bLength = USB_DT_INTERFACE_SIZE,
.bDescriptorType = USB_DT_INTERFACE,
.bInterfaceNumber = 1,
.bAlternateSetting = 0,
.bNumEndpoints = 2,
.bInterfaceClass = USB_CLASS_DATA,
.bInterfaceSubClass = 0,
.bInterfaceProtocol = 0,
.iInterface = 0,

.endpoint = data_endp,
}};


static const struct usb_interface ifaces[] =
{
{
.num_altsetting = 1,
.altsetting = comm_iface,
},

{
.num_altsetting = 1,
.altsetting = data_iface,
}
};


static const struct usb_config_descriptor config =
{
.bLength = USB_DT_CONFIGURATION_SIZE,
.bDescriptorType = USB_DT_CONFIGURATION,
.wTotalLength = 0,
.bNumInterfaces = 2,
.bConfigurationValue = 1,
.iConfiguration = 0,
.bmAttributes = 0x80,
.bMaxPower = 0x32,

.interface = ifaces,
};


static const char *usb_strings[] =
{
"VUT - BROB projekt",
"Inductor-tester",
"DEMO",
};


// Buffer to be used for control requests.

static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req));

static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep);

static void cdcacm_set_config(usbd_device *usbd_dev, uint16_t wValue);


#endif
27 changes: 22 additions & 5 deletions fw/f4discovery/project.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@
</Build>
<Unit filename="Makefile" />
<Unit filename="include/current.h" />
<Unit filename="include/dac.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="include/leds.h" />
<Unit filename="include/primitives/llist.h" />
<Unit filename="include/primitives/ringbuf.h" />
<Unit filename="include/protokol.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="include/pwm.h" />
<Unit filename="include/serial.h" />
<Unit filename="include/usb_vilem.h" />
<Unit filename="lib/libopencm3/include/libopencm3/cm3/assert.h" />
<Unit filename="lib/libopencm3/include/libopencm3/cm3/common.h" />
<Unit filename="lib/libopencm3/include/libopencm3/cm3/cortex.h" />
Expand Down Expand Up @@ -873,6 +880,10 @@
<Unit filename="src/current.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/dac.c">
<Option compilerVar="CC" />
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="src/leds.c">
<Option compilerVar="CC" />
</Unit>
Expand All @@ -885,27 +896,33 @@
<Unit filename="src/primitives/ringbuf.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/protokol.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/pwm.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/serial.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/usb_vilem.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<code_completion />
<envvars />
<debugger>
<remote_debugging target="Release">
<options conn_type="2" serial_port="COM3" serial_baud="115200" ip_address="localhost" ip_port="3333" additional_cmds="monitor swdp_scan&#x0A;attach 1&#x0A;load&#x0A;run" extended_remote="1" />
</remote_debugging>
<remote_debugging target="Debug">
<options conn_type="2" serial_port="COM3" serial_baud="115200" ip_address="localhost" ip_port="3333" additional_cmds="monitor connect_srst enable&#x0A;monitor swdp_scan&#x0A;attach 1&#x0A;load&#x0A;b main&#x0A;run" extended_remote="1" />
<options conn_type="2" serial_port="COM4" serial_baud="115200" ip_address="localhost" ip_port="3333" additional_cmds="monitor connect_srst enable&#x0A;monitor swdp_scan&#x0A;attach 1&#x0A;load&#x0A;b main&#x0A;run" extended_remote="1" />
</remote_debugging>
<remote_debugging target="Release">
<options conn_type="2" serial_port="COM4" serial_baud="115200" ip_address="localhost" ip_port="3333" additional_cmds="monitor swdp_scan&#x0A;attach 1&#x0A;load&#x0A;run" extended_remote="1" />
</remote_debugging>
</debugger>
<lib_finder disable_auto="1" />
<DoxyBlocks>
<comment_style block="0" line="0" />
<doxyfile_project />
<doxyfile_project output_language="Czech" />
<doxyfile_build />
<doxyfile_warnings />
<doxyfile_output />
Expand Down
Loading