some code fixes, start to draw new schematic

This commit is contained in:
Edward Emelianov 2024-03-19 23:42:48 +03:00
parent ad92546f82
commit e92a5c4234
22 changed files with 156780 additions and 20670 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,10 +3,12 @@
"active_layer": 0, "active_layer": 0,
"active_layer_preset": "", "active_layer_preset": "",
"auto_track_width": true, "auto_track_width": true,
"hidden_netclasses": [],
"hidden_nets": [], "hidden_nets": [],
"high_contrast_mode": 0, "high_contrast_mode": 0,
"net_color_mode": 1, "net_color_mode": 1,
"opacity": { "opacity": {
"images": 0.6,
"pads": 1.0, "pads": 1.0,
"tracks": 1.0, "tracks": 1.0,
"vias": 1.0, "vias": 1.0,
@ -63,7 +65,13 @@
36 36
], ],
"visible_layers": "fffffff_ffffffff", "visible_layers": "fffffff_ffffffff",
"zone_display_mode": 0 "zone_display_mode": 1
},
"git": {
"repo_password": "",
"repo_type": "",
"repo_username": "",
"ssh_key": ""
}, },
"meta": { "meta": {
"filename": "stm32.kicad_prl", "filename": "stm32.kicad_prl",
@ -71,5 +79,18 @@
}, },
"project": { "project": {
"files": [] "files": []
},
"schematic": {
"selection_filter": {
"graphics": true,
"images": true,
"labels": true,
"lockedItems": false,
"otherItems": true,
"pins": true,
"symbols": true,
"text": true,
"wires": true
}
} }
} }

View File

@ -1,64 +1,222 @@
{ {
"board": { "board": {
"3dviewports": [],
"design_settings": { "design_settings": {
"defaults": { "defaults": {
"apply_defaults_to_fp_fields": false,
"apply_defaults_to_fp_shapes": false,
"apply_defaults_to_fp_text": false,
"board_outline_line_width": 0.15, "board_outline_line_width": 0.15,
"copper_line_width": 0.2, "copper_line_width": 0.2,
"copper_text_italic": false, "copper_text_italic": false,
"copper_text_size_h": 1.5, "copper_text_size_h": 1.5,
"copper_text_size_v": 1.5, "copper_text_size_v": 1.5,
"copper_text_thickness": 0.3, "copper_text_thickness": 0.3,
"copper_text_upright": true, "copper_text_upright": false,
"courtyard_line_width": 0.05, "courtyard_line_width": 0.05,
"other_line_width": 0.15, "dimension_precision": 4,
"dimension_units": 3,
"dimensions": {
"arrow_length": 1270000,
"extension_offset": 500000,
"keep_text_aligned": true,
"suppress_zeroes": false,
"text_position": 0,
"units_format": 1
},
"fab_line_width": 0.1,
"fab_text_italic": false,
"fab_text_size_h": 1.0,
"fab_text_size_v": 1.0,
"fab_text_thickness": 0.15,
"fab_text_upright": false,
"other_line_width": 0.1,
"other_text_italic": false, "other_text_italic": false,
"other_text_size_h": 1.0, "other_text_size_h": 1.0,
"other_text_size_v": 1.0, "other_text_size_v": 1.0,
"other_text_thickness": 0.15, "other_text_thickness": 0.15,
"other_text_upright": true, "other_text_upright": false,
"pads": {
"drill": 0.8,
"height": 1.5,
"width": 1.5
},
"silk_line_width": 0.15, "silk_line_width": 0.15,
"silk_text_italic": false, "silk_text_italic": false,
"silk_text_size_h": 1.0, "silk_text_size_h": 1.0,
"silk_text_size_v": 1.0, "silk_text_size_v": 1.0,
"silk_text_thickness": 0.15, "silk_text_thickness": 0.15,
"silk_text_upright": true "silk_text_upright": false,
}, "zones": {
"diff_pair_dimensions": [ "min_clearance": 0.5
{
"gap": 0.25,
"via_gap": 0.25,
"width": 0.2
} }
], },
"diff_pair_dimensions": [],
"drc_exclusions": [], "drc_exclusions": [],
"meta": {
"filename": "board_design_settings.json",
"version": 2
},
"rule_severities": {
"annular_width": "error",
"clearance": "error",
"connection_width": "warning",
"copper_edge_clearance": "error",
"copper_sliver": "warning",
"courtyards_overlap": "error",
"diff_pair_gap_out_of_range": "error",
"diff_pair_uncoupled_length_too_long": "error",
"drill_out_of_range": "error",
"duplicate_footprints": "warning",
"extra_footprint": "warning",
"footprint": "error",
"footprint_symbol_mismatch": "warning",
"footprint_type_mismatch": "ignore",
"hole_clearance": "error",
"hole_near_hole": "error",
"invalid_outline": "error",
"isolated_copper": "warning",
"item_on_disabled_layer": "error",
"items_not_allowed": "error",
"length_out_of_range": "error",
"lib_footprint_issues": "warning",
"lib_footprint_mismatch": "warning",
"malformed_courtyard": "error",
"microvia_drill_out_of_range": "error",
"missing_courtyard": "ignore",
"missing_footprint": "warning",
"net_conflict": "warning",
"npth_inside_courtyard": "ignore",
"padstack": "warning",
"pth_inside_courtyard": "ignore",
"shorting_items": "error",
"silk_edge_clearance": "warning",
"silk_over_copper": "warning",
"silk_overlap": "warning",
"skew_out_of_range": "error",
"solder_mask_bridge": "error",
"starved_thermal": "error",
"text_height": "warning",
"text_thickness": "warning",
"through_hole_pad_without_hole": "error",
"too_many_vias": "error",
"track_dangling": "warning",
"track_width": "error",
"tracks_crossing": "error",
"unconnected_items": "error",
"unresolved_variable": "error",
"via_dangling": "warning",
"zones_intersect": "error"
},
"rule_severitieslegacy_courtyards_overlap": true, "rule_severitieslegacy_courtyards_overlap": true,
"rule_severitieslegacy_no_courtyard_defined": false, "rule_severitieslegacy_no_courtyard_defined": false,
"rules": { "rules": {
"allow_blind_buried_vias": false, "allow_blind_buried_vias": false,
"allow_microvias": false, "allow_microvias": false,
"max_error": 0.005,
"min_clearance": 0.0,
"min_connection": 0.0,
"min_copper_edge_clearance": 0.075,
"min_hole_clearance": 0.25,
"min_hole_to_hole": 0.25, "min_hole_to_hole": 0.25,
"min_microvia_diameter": 0.2, "min_microvia_diameter": 0.2,
"min_microvia_drill": 0.09999999999999999, "min_microvia_drill": 0.1,
"min_resolved_spokes": 2,
"min_silk_clearance": 0.0,
"min_text_height": 0.8,
"min_text_thickness": 0.08,
"min_through_hole_diameter": 0.5, "min_through_hole_diameter": 0.5,
"min_track_width": 0.2, "min_track_width": 0.2,
"min_via_diameter": 0.7999999999999999, "min_via_annular_width": 0.1,
"min_via_diameter": 0.8,
"solder_mask_clearance": 0.2, "solder_mask_clearance": 0.2,
"solder_mask_min_width": 0.0, "solder_mask_min_width": 0.0,
"solder_mask_to_copper_clearance": 0.0,
"solder_paste_clearance": 0.0, "solder_paste_clearance": 0.0,
"solder_paste_margin_ratio": -0.0 "solder_paste_margin_ratio": -0.0,
"use_height_for_length_calcs": true
}, },
"teardrop_options": [
{
"td_onpadsmd": true,
"td_onroundshapesonly": false,
"td_ontrackend": false,
"td_onviapad": true
}
],
"teardrop_parameters": [
{
"td_allow_use_two_tracks": true,
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_on_pad_in_zone": false,
"td_target_name": "td_round_shape",
"td_width_to_size_filter_ratio": 0.9
},
{
"td_allow_use_two_tracks": true,
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_on_pad_in_zone": false,
"td_target_name": "td_rect_shape",
"td_width_to_size_filter_ratio": 0.9
},
{
"td_allow_use_two_tracks": true,
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_on_pad_in_zone": false,
"td_target_name": "td_track_end",
"td_width_to_size_filter_ratio": 0.9
}
],
"track_widths": [ "track_widths": [
0.2, 0.0,
0.2, 0.2,
0.3, 0.3,
0.5, 0.5,
1.0, 1.0,
2.0 2.0
], ],
"tuning_pattern_settings": {
"diff_pair_defaults": {
"corner_radius_percentage": 80,
"corner_style": 1,
"max_amplitude": 1.0,
"min_amplitude": 0.2,
"single_sided": false,
"spacing": 1.0
},
"diff_pair_skew_defaults": {
"corner_radius_percentage": 80,
"corner_style": 1,
"max_amplitude": 1.0,
"min_amplitude": 0.2,
"single_sided": false,
"spacing": 0.6
},
"single_track_defaults": {
"corner_radius_percentage": 80,
"corner_style": 1,
"max_amplitude": 1.0,
"min_amplitude": 0.2,
"single_sided": false,
"spacing": 0.6
}
},
"via_dimensions": [ "via_dimensions": [
{ {
"diameter": 1.0, "diameter": 0.0,
"drill": 0.6 "drill": 0.0
}, },
{ {
"diameter": 1.0, "diameter": 1.0,
@ -68,9 +226,18 @@
"diameter": 1.5, "diameter": 1.5,
"drill": 0.8 "drill": 0.8
} }
] ],
"zones_allow_external_fillets": false
}, },
"layer_presets": [] "ipc2581": {
"dist": "",
"distpn": "",
"internal_id": "",
"mfg": "",
"mpn": ""
},
"layer_presets": [],
"viewports": []
}, },
"boards": [], "boards": [],
"cvpcb": { "cvpcb": {
@ -257,15 +424,23 @@
"bus_label_syntax": "error", "bus_label_syntax": "error",
"bus_to_bus_conflict": "error", "bus_to_bus_conflict": "error",
"bus_to_net_conflict": "error", "bus_to_net_conflict": "error",
"conflicting_netclasses": "error",
"different_unit_footprint": "error", "different_unit_footprint": "error",
"different_unit_net": "error", "different_unit_net": "error",
"duplicate_reference": "error", "duplicate_reference": "error",
"duplicate_sheet_names": "error", "duplicate_sheet_names": "error",
"endpoint_off_grid": "warning",
"extra_units": "error", "extra_units": "error",
"footprint_link_issues": "warning",
"global_label_dangling": "warning", "global_label_dangling": "warning",
"hier_label_mismatch": "error", "hier_label_mismatch": "error",
"label_dangling": "error", "label_dangling": "error",
"lib_symbol_issues": "warning", "lib_symbol_issues": "warning",
"lib_symbol_mismatch": "warning",
"missing_bidi_pin": "warning",
"missing_input_pin": "warning",
"missing_power_pin": "error",
"missing_unit": "warning",
"multiple_net_names": "warning", "multiple_net_names": "warning",
"net_not_bus_member": "warning", "net_not_bus_member": "warning",
"no_connect_connected": "warning", "no_connect_connected": "warning",
@ -275,6 +450,7 @@
"pin_to_pin": "warning", "pin_to_pin": "warning",
"power_pin_not_driven": "error", "power_pin_not_driven": "error",
"similar_labels": "warning", "similar_labels": "warning",
"simulation_model_issue": "ignore",
"unannotated": "error", "unannotated": "error",
"unit_value_mismatch": "error", "unit_value_mismatch": "error",
"unresolved_variable": "error", "unresolved_variable": "error",
@ -292,7 +468,7 @@
"net_settings": { "net_settings": {
"classes": [ "classes": [
{ {
"bus_width": 12.0, "bus_width": 12,
"clearance": 0.2, "clearance": 0.2,
"diff_pair_gap": 0.25, "diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25, "diff_pair_via_gap": 0.25,
@ -303,31 +479,375 @@
"name": "Default", "name": "Default",
"pcb_color": "rgba(0, 0, 0, 0.000)", "pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)", "schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 0.25, "track_width": 0.2,
"via_diameter": 0.8, "via_diameter": 1.0,
"via_drill": 0.4, "via_drill": 0.6,
"wire_width": 6.0 "wire_width": 6
},
{
"bus_width": 12,
"clearance": 0.3,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.2,
"line_style": 0,
"microvia_diameter": 0.3,
"microvia_drill": 0.1,
"name": "0.5",
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 0.5,
"via_diameter": 1.0,
"via_drill": 0.6,
"wire_width": 6
},
{
"bus_width": 12,
"clearance": 0.5,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.2,
"line_style": 0,
"microvia_diameter": 0.3,
"microvia_drill": 0.1,
"name": "1",
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 1.0,
"via_diameter": 1.5,
"via_drill": 0.8,
"wire_width": 6
} }
], ],
"meta": { "meta": {
"version": 2 "version": 3
}, },
"net_colors": null "net_colors": null,
"netclass_assignments": null,
"netclass_patterns": [
{
"netclass": "Default",
"pattern": "+3V3"
},
{
"netclass": "Default",
"pattern": "+5V"
},
{
"netclass": "Default",
"pattern": "/5Vin"
},
{
"netclass": "Default",
"pattern": "/5Vusb"
},
{
"netclass": "Default",
"pattern": "/AIN0"
},
{
"netclass": "Default",
"pattern": "/AIN1"
},
{
"netclass": "Default",
"pattern": "/BOOT0"
},
{
"netclass": "Default",
"pattern": "/CAN_Rx"
},
{
"netclass": "Default",
"pattern": "/CAN_Tx"
},
{
"netclass": "Default",
"pattern": "/DIR"
},
{
"netclass": "Default",
"pattern": "/ESW0"
},
{
"netclass": "Default",
"pattern": "/ESW1"
},
{
"netclass": "Default",
"pattern": "/ESW2"
},
{
"netclass": "Default",
"pattern": "/ESW3"
},
{
"netclass": "Default",
"pattern": "/MISO"
},
{
"netclass": "Default",
"pattern": "/MOSI"
},
{
"netclass": "Default",
"pattern": "/NRST"
},
{
"netclass": "Default",
"pattern": "/Rx"
},
{
"netclass": "Default",
"pattern": "/SCK"
},
{
"netclass": "Default",
"pattern": "/STEP"
},
{
"netclass": "Default",
"pattern": "/SWCLK"
},
{
"netclass": "Default",
"pattern": "/SWDIO"
},
{
"netclass": "Default",
"pattern": "/Tx"
},
{
"netclass": "Default",
"pattern": "/Tx|Rx"
},
{
"netclass": "Default",
"pattern": "/VIO_on"
},
{
"netclass": "Default",
"pattern": "/brdaddr0"
},
{
"netclass": "Default",
"pattern": "/brdaddr1"
},
{
"netclass": "Default",
"pattern": "/brdaddr2"
},
{
"netclass": "Default",
"pattern": "/brdaddr3"
},
{
"netclass": "Default",
"pattern": "/~{CS}"
},
{
"netclass": "Default",
"pattern": "/~{EN}"
},
{
"netclass": "Default",
"pattern": "/~{FAULT}"
},
{
"netclass": "Default",
"pattern": "/~{SLEEP}"
},
{
"netclass": "Default",
"pattern": "GND"
},
{
"netclass": "Default",
"pattern": "Net-(D4-Pad1)"
},
{
"netclass": "Default",
"pattern": "Net-(D4-Pad2)"
},
{
"netclass": "Default",
"pattern": "Net-(D5-Pad2)"
},
{
"netclass": "Default",
"pattern": "Net-(D6-Pad2)"
},
{
"netclass": "Default",
"pattern": "Net-(D6-Pad3)"
},
{
"netclass": "Default",
"pattern": "Net-(D6-Pad6)"
},
{
"netclass": "Default",
"pattern": "Net-(D6-Pad7)"
},
{
"netclass": "Default",
"pattern": "Net-(F1-Pad1)"
},
{
"netclass": "Default",
"pattern": "Net-(F1-Pad2)"
},
{
"netclass": "Default",
"pattern": "Net-(J1-Pad1)"
},
{
"netclass": "Default",
"pattern": "Net-(J1-Pad2)"
},
{
"netclass": "Default",
"pattern": "Net-(J12-Pad1)"
},
{
"netclass": "Default",
"pattern": "Net-(J12-Pad2)"
},
{
"netclass": "Default",
"pattern": "Net-(J13-Pad6)"
},
{
"netclass": "Default",
"pattern": "Net-(J2-Pad1)"
},
{
"netclass": "Default",
"pattern": "Net-(J2-Pad2)"
},
{
"netclass": "Default",
"pattern": "Net-(J5-Pad1)"
},
{
"netclass": "Default",
"pattern": "Net-(J7-Pad1)"
},
{
"netclass": "Default",
"pattern": "Net-(J7-Pad2)"
},
{
"netclass": "Default",
"pattern": "Net-(J8-Pad1)"
},
{
"netclass": "Default",
"pattern": "Net-(J8-Pad2)"
},
{
"netclass": "Default",
"pattern": "Net-(Q1-Pad1)"
},
{
"netclass": "Default",
"pattern": "Net-(R11-Pad2)"
},
{
"netclass": "Default",
"pattern": "Net-(R12-Pad2)"
},
{
"netclass": "Default",
"pattern": "Net-(R4-Pad1)"
},
{
"netclass": "Default",
"pattern": "Net-(R9-Pad1)"
},
{
"netclass": "0.5",
"pattern": "/12Vin"
}
]
}, },
"pcbnew": { "pcbnew": {
"last_paths": { "last_paths": {
"gencad": "", "gencad": "",
"idf": "", "idf": "",
"netlist": "stm32.net", "netlist": "stm32.net",
"plot": "",
"pos_files": "",
"specctra_dsn": "", "specctra_dsn": "",
"step": "", "step": "",
"svg": "",
"vrml": "" "vrml": ""
}, },
"page_layout_descr_file": "" "page_layout_descr_file": ""
}, },
"schematic": { "schematic": {
"annotate_start_num": 0, "annotate_start_num": 0,
"bom_fmt_presets": [],
"bom_fmt_settings": {
"field_delimiter": ",",
"keep_line_breaks": false,
"keep_tabs": false,
"name": "CSV",
"ref_delimiter": ",",
"ref_range_delimiter": "",
"string_delimiter": "\""
},
"bom_presets": [],
"bom_settings": {
"exclude_dnp": false,
"fields_ordered": [
{
"group_by": false,
"label": "Reference",
"name": "Reference",
"show": true
},
{
"group_by": true,
"label": "Value",
"name": "Value",
"show": true
},
{
"group_by": false,
"label": "Datasheet",
"name": "Datasheet",
"show": true
},
{
"group_by": false,
"label": "Footprint",
"name": "Footprint",
"show": true
},
{
"group_by": false,
"label": "Qty",
"name": "${QUANTITY}",
"show": true
},
{
"group_by": true,
"label": "DNP",
"name": "${DNP}",
"show": true
}
],
"filter_string": "",
"group_symbols": true,
"name": "Grouped By Value",
"sort_asc": true,
"sort_field": "Reference"
},
"connection_grid_size": 50.0,
"drawing": { "drawing": {
"dashed_lines_dash_length_ratio": 12.0,
"dashed_lines_gap_length_ratio": 3.0,
"default_line_thickness": 6.0, "default_line_thickness": 6.0,
"default_text_size": 50.0, "default_text_size": 50.0,
"field_names": [], "field_names": [],
@ -338,6 +858,11 @@
"intersheets_ref_suffix": "", "intersheets_ref_suffix": "",
"junction_size_choice": 3, "junction_size_choice": 3,
"label_size_ratio": 0.25, "label_size_ratio": 0.25,
"operating_point_overlay_i_precision": 3,
"operating_point_overlay_i_range": "~A",
"operating_point_overlay_v_precision": 3,
"operating_point_overlay_v_range": "~V",
"overbar_offset_ratio": 1.23,
"pin_symbol_size": 0.0, "pin_symbol_size": 0.0,
"text_offset_ratio": 0.08 "text_offset_ratio": 0.08
}, },
@ -359,14 +884,19 @@
"page_layout_descr_file": "", "page_layout_descr_file": "",
"plot_directory": "", "plot_directory": "",
"spice_adjust_passive_values": false, "spice_adjust_passive_values": false,
"spice_current_sheet_as_root": false,
"spice_external_command": "spice \"%I\"", "spice_external_command": "spice \"%I\"",
"spice_model_current_sheet_as_root": true,
"spice_save_all_currents": false,
"spice_save_all_dissipations": false,
"spice_save_all_voltages": false,
"subpart_first_id": 49, "subpart_first_id": 49,
"subpart_id_separator": 46 "subpart_id_separator": 46
}, },
"sheets": [ "sheets": [
[ [
"99e5cbe8-ca46-48a4-a6fc-cabce62e3612", "99e5cbe8-ca46-48a4-a6fc-cabce62e3612",
"" "Root"
] ]
], ],
"text_variables": {} "text_variables": {}

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 12.0.2, 2024-03-07T19:39:35. --> <!-- Written by QtCreator 12.0.2, 2024-03-18T00:40:28. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

View File

@ -133,6 +133,11 @@ static errcodes initspi2(CAN_message _U_ *msg){
spi_setup(2); spi_setup(2);
return ERR_OK; return ERR_OK;
} }
// deinit SPI2
static errcodes deinitspi2(CAN_message _U_ *msg){
spi_deinit(2);
return ERR_OK;
}
// send/read 1..4 bytes // send/read 1..4 bytes
static errcodes sendspi2(CAN_message *msg){ static errcodes sendspi2(CAN_message *msg){
int n = msg->length - 4; int n = msg->length - 4;
@ -175,6 +180,7 @@ static errcodes flagsetget(CAN_message *msg){
uint8_t bit = 32; uint8_t bit = 32;
switch(idx){ switch(idx){
case CMD_ENCISSSI: bit = FLAGBIT(ENC_IS_SSI); break; case CMD_ENCISSSI: bit = FLAGBIT(ENC_IS_SSI); break;
case CMD_EMULPEP: bit = FLAGBIT(EMULATE_PEP); break;
default: break; default: break;
} }
if(bit > 31) return ERR_CANTRUN; // unknown error if(bit > 31) return ERR_CANTRUN; // unknown error
@ -220,6 +226,7 @@ static const commonfunction funclist[CMD_AMOUNT] = {
[CMD_EMULPEP] = {flagsetget, 0, 0, 0}, [CMD_EMULPEP] = {flagsetget, 0, 0, 0},
[CMD_ENCREINIT] = {encreinit, 0, 0, 0}, [CMD_ENCREINIT] = {encreinit, 0, 0, 0},
[CMD_TIMESTAMP] = {timestamp_getset, 0, 0xffffff, 0}, [CMD_TIMESTAMP] = {timestamp_getset, 0, 0xffffff, 0},
[CMD_SPIDEINIT] = {deinitspi2, 0, 0, 0},
}; };

View File

@ -38,9 +38,24 @@ void encoder_setup(){
// read encoder value into buffer `outbuf` // read encoder value into buffer `outbuf`
// return TRUE if all OK // return TRUE if all OK
int read_encoder(uint8_t outbuf[4]){ int read_encoder(uint8_t outbuf[4]){
if(!FLAG(ENC_IS_SSI)) return FALSE;
*((uint32_t*)outbuf) = 0; *((uint32_t*)outbuf) = 0;
return spi_writeread(ENCODER_SPI, outbuf, 4); if(FLAG(ENC_IS_SSI)){
int r = spi_read(ENCODER_SPI, outbuf, 4);
return r;
}
usart_rstbuf();
// just send some trash over USART1 if encoder is RS-422
usart_send("teststring\n");
char *x;
uint32_t Tl = Tms;
while(Tms - Tl < 10){
int l = usart_getline(&x);
if(l){
for(int i = 0; i < l && i < 4; ++i) outbuf[i] = x[i];
return TRUE;
}
}
return FALSE;
} }
// send encoder data // send encoder data
@ -57,7 +72,6 @@ void CANsendEnc(){
// send limit-switches data // send limit-switches data
void CANsendLim(){ void CANsendLim(){
CAN_message msg = {.data = {0}, .ID = the_conf.limitsID, .length = 8}; CAN_message msg = {.data = {0}, .ID = the_conf.limitsID, .length = 8};
msg.data[2] = getESW(0); msg.data[2] = getESW(1);
msg.data[3] = getESW(1);
CAN_send(&msg); CAN_send(&msg);
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,11 @@
(generator_version "8.99") (generator_version "8.99")
(uuid "c774fcd8-2321-49e3-82b6-f080291ee83c") (uuid "c774fcd8-2321-49e3-82b6-f080291ee83c")
(paper "A4") (paper "A4")
(title_block
(date "2024-03-18")
(company "SAO RAS")
(comment 1 "Instead of PEP controller")
)
(lib_symbols (lib_symbols
(symbol "Device:R" (symbol "Device:R"
(pin_numbers hide) (pin_numbers hide)
@ -518,7 +523,7 @@
(justify left) (justify left)
) )
) )
(property "Value" "360" (property "Value" "3k3"
(at 109.093 51.943 90) (at 109.093 51.943 90)
(effects (effects
(font (font
@ -527,7 +532,7 @@
(justify left) (justify left)
) )
) )
(property "Footprint" "Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder" (property "Footprint" "Resistor_SMD:R_2010_5025Metric_Pad1.40x2.65mm_HandSolder"
(at 107.442 50.419 90) (at 107.442 50.419 90)
(effects (effects
(font (font

View File

@ -65,7 +65,7 @@
36 36
], ],
"visible_layers": "fffffff_ffffffff", "visible_layers": "fffffff_ffffffff",
"zone_display_mode": 0 "zone_display_mode": 1
}, },
"git": { "git": {
"repo_password": "", "repo_password": "",

View File

@ -565,11 +565,29 @@
"label": "DNP", "label": "DNP",
"name": "${DNP}", "name": "${DNP}",
"show": true "show": true
},
{
"group_by": false,
"label": "#",
"name": "${ITEM_NUMBER}",
"show": false
},
{
"group_by": false,
"label": "Manufacturer",
"name": "Manufacturer",
"show": false
},
{
"group_by": false,
"label": "Description",
"name": "Description",
"show": false
} }
], ],
"filter_string": "", "filter_string": "",
"group_symbols": true, "group_symbols": true,
"name": "Grouped By Value", "name": "",
"sort_asc": true, "sort_asc": true,
"sort_field": "Reference" "sort_field": "Reference"
}, },
@ -619,8 +637,8 @@
"spice_save_all_currents": false, "spice_save_all_currents": false,
"spice_save_all_dissipations": false, "spice_save_all_dissipations": false,
"spice_save_all_voltages": false, "spice_save_all_voltages": false,
"subpart_first_id": 65, "subpart_first_id": 49,
"subpart_id_separator": 0 "subpart_id_separator": 46
}, },
"sheets": [ "sheets": [
[ [

File diff suppressed because it is too large Load Diff

View File

@ -72,6 +72,7 @@ typedef enum{
CMD_EMULPEP, // 19 - emulate (1) / not (0) PEP CMD_EMULPEP, // 19 - emulate (1) / not (0) PEP
CMD_ENCREINIT, // 20 - reinit encoder CMD_ENCREINIT, // 20 - reinit encoder
CMD_TIMESTAMP, // 21 - 2mks 24-bit timestamp CMD_TIMESTAMP, // 21 - 2mks 24-bit timestamp
CMD_SPIDEINIT, // 22 - turn off SPI2
CMD_AMOUNT // amount of CAN commands CMD_AMOUNT // amount of CAN commands
} can_cmd; } can_cmd;

View File

@ -81,10 +81,17 @@ void spi_setup(uint8_t idx){
// DS=8bit; RXNE generates after 8bit of data in FIFO; // DS=8bit; RXNE generates after 8bit of data in FIFO;
SPI->CR2 |= SPI_CR2_FRXTH | SPI_CR2_DS_2|SPI_CR2_DS_1|SPI_CR2_DS_0; SPI->CR2 |= SPI_CR2_FRXTH | SPI_CR2_DS_2|SPI_CR2_DS_1|SPI_CR2_DS_0;
spi_status[idx] = SPI_READY; spi_status[idx] = SPI_READY;
SPI->CR1 |= SPI_CR1_SPE; if(idx == 2) SPI->CR1 |= SPI_CR1_SPE; // turn on SPI1 only when reading data
DBG("SPI works"); DBG("SPI works");
} }
void spi_onoff(uint8_t idx, uint8_t on){
CHKIDX(idx);
volatile SPI_TypeDef *SPI = SPIs[idx];
if(on) SPI->CR1 |= SPI_CR1_SPE;
else SPI->CR1 &= ~SPI_CR1_SPE;
}
// turn off given SPI channel and release GPIO // turn off given SPI channel and release GPIO
void spi_deinit(uint8_t idx){ void spi_deinit(uint8_t idx){
CHKIDX(idx); CHKIDX(idx);
@ -100,6 +107,7 @@ void spi_deinit(uint8_t idx){
GPIOB->AFR[1] = GPIOB->AFR[1] & ~(GPIO_AFRH_AFRH4 | GPIO_AFRH_AFRH5 | GPIO_AFRH_AFRH6 | GPIO_AFRH_AFRH7); GPIOB->AFR[1] = GPIOB->AFR[1] & ~(GPIO_AFRH_AFRH4 | GPIO_AFRH_AFRH5 | GPIO_AFRH_AFRH6 | GPIO_AFRH_AFRH7);
GPIOB->MODER = GPIOB->MODER & ~(GPIO_MODER_MODER12 | GPIO_MODER_MODER13 | GPIO_MODER_MODER14 | GPIO_MODER_MODER15); GPIOB->MODER = GPIOB->MODER & ~(GPIO_MODER_MODER12 | GPIO_MODER_MODER13 | GPIO_MODER_MODER14 | GPIO_MODER_MODER15);
} }
spi_status[idx] = SPI_NOTREADY;
} }
int spi_waitbsy(uint8_t idx){ int spi_waitbsy(uint8_t idx){
@ -120,6 +128,8 @@ int spi_writeread(uint8_t idx, uint8_t *data, uint32_t n){
DBG("not ready"); DBG("not ready");
return 0; return 0;
} }
// clear SPI Rx FIFO
for(int i = 0; i < 4; ++i) (void) SPI2->DR;
for(uint32_t x = 0; x < n; ++x){ for(uint32_t x = 0; x < n; ++x){
WAITX(!(SPIs[idx]->SR & SPI_SR_TXE)); WAITX(!(SPIs[idx]->SR & SPI_SR_TXE));
*((volatile uint8_t*)&SPIs[idx]->DR) = data[x]; *((volatile uint8_t*)&SPIs[idx]->DR) = data[x];
@ -129,6 +139,26 @@ int spi_writeread(uint8_t idx, uint8_t *data, uint32_t n){
return 1; return 1;
} }
// read data through SPI in read-only mode
int spi_read(uint8_t idx, uint8_t *data, uint32_t n){
CHKIDXR(idx);
if(spi_status[idx] != SPI_READY || !data || !n){
DBG("not ready");
return 0;
}
// clear SPI Rx FIFO
for(int i = 0; i < 4; ++i) (void) SPI2->DR;
spi_onoff(idx, TRUE);
for(uint32_t x = 0; x < n; ++x){
if(x == n - 1) SPIs[idx]->CR1 &= ~SPI_CR1_RXONLY;
WAITX(!(SPIs[idx]->SR & SPI_SR_RXNE));
data[x] = *((volatile uint8_t*)&SPIs[idx]->DR);
}
spi_onoff(idx, FALSE);
SPIs[idx]->CR1 |= SPI_CR1_RXONLY;
return 1;
}
/** /**
* @brief spi_send_dma - send data over SPI2 through DMA (used both for writing and reading) * @brief spi_send_dma - send data over SPI2 through DMA (used both for writing and reading)
* @param data - data to read * @param data - data to read

View File

@ -29,10 +29,12 @@ typedef enum{
extern spiStatus spi_status[AMOUNT_OF_SPI+1]; extern spiStatus spi_status[AMOUNT_OF_SPI+1];
void spi_onoff(uint8_t idx, uint8_t on);
void spi_deinit(uint8_t idx); void spi_deinit(uint8_t idx);
void spi_setup(uint8_t idx); void spi_setup(uint8_t idx);
int spi_waitbsy(uint8_t idx); int spi_waitbsy(uint8_t idx);
int spi_writeread(uint8_t idx, uint8_t *data, uint32_t n); int spi_writeread(uint8_t idx, uint8_t *data, uint32_t n);
int spi_read(uint8_t idx, uint8_t *data, uint32_t n);
//int spi_write_dma(const uint8_t *data, uint8_t *rxbuf, uint32_t n); //int spi_write_dma(const uint8_t *data, uint8_t *rxbuf, uint32_t n);
//int spi_read(uint8_t idx, uint8_t *data, uint32_t n); //int spi_read(uint8_t idx, uint8_t *data, uint32_t n);
//uint8_t *spi_read_dma(uint32_t *n); //uint8_t *spi_read_dma(uint32_t *n);

View File

@ -263,8 +263,11 @@ const char *getint(const char *txt, int32_t *I){
} }
const char *nxt = getnum(s, &U); const char *nxt = getnum(s, &U);
if(nxt == s) return txt; if(nxt == s) return txt;
if(U & 0x80000000) return txt; // overfull if(U & 0x80000000){ // uint32_t
*I = sign * (int32_t)U; *I = (int32_t)U;
}else{
*I = sign * (int32_t)U;
}
return nxt; return nxt;
} }

View File

@ -70,6 +70,7 @@ static const funcdescr funclist[] = {
{"reset", CMD_RESET, "reset MCU"}, {"reset", CMD_RESET, "reset MCU"},
{"s", -TCMD_CANSEND, "send CAN message: ID 0..8 data bytes"}, {"s", -TCMD_CANSEND, "send CAN message: ID 0..8 data bytes"},
{"saveconf", CMD_SAVECONF, "save configuration"}, {"saveconf", CMD_SAVECONF, "save configuration"},
{"spideinit", CMD_SPIDEINIT, "turn off SPI2"},
{"spiinit", CMD_SPIINIT, "init SPI2"}, {"spiinit", CMD_SPIINIT, "init SPI2"},
{"spisend", CMD_SPISEND, "send 4 bytes over SPI2"}, {"spisend", CMD_SPISEND, "send 4 bytes over SPI2"},
{"time", CMD_TIME, "get/set time (1ms, 32bit)"}, {"time", CMD_TIME, "get/set time (1ms, 32bit)"},
@ -90,6 +91,7 @@ static errcodes wdtest(const char _U_ *str){
// names of bit flags (ordered from LSE of[0]) // names of bit flags (ordered from LSE of[0])
static const char * const bitfields[] = { static const char * const bitfields[] = {
"encisSSI", "encisSSI",
"emulatePEP",
NULL NULL
}; };
@ -112,7 +114,7 @@ static errcodes dumpconf(const char _U_ *str){
USB_sendstr("\nusartspeed="); printu(the_conf.usartspeed); USB_sendstr("\nusartspeed="); printu(the_conf.usartspeed);
const char * const *p = bitfields; const char * const *p = bitfields;
int bit = 0; int bit = 0;
while(p){ while(*p){
newline(); newline();
USB_sendstr(*p); USB_putbyte('='); USB_putbyte((the_conf.flags & (1<<bit)) ? '1' : '0'); USB_sendstr(*p); USB_putbyte('='); USB_putbyte((the_conf.flags & (1<<bit)) ? '1' : '0');
if(++bit > 31) break; if(++bit > 31) break;

View File

@ -32,6 +32,14 @@ static volatile int rbufno = 0; // current rbuf number
static char rbuf[2][UARTBUFSZ]; // receive buffers static char rbuf[2][UARTBUFSZ]; // receive buffers
static volatile char *recvdata = NULL; static volatile char *recvdata = NULL;
// reset incoming buffer
void usart_rstbuf(){
linerdy = 0;
dlen = 0;
bufovr = 0;
recvdata = NULL;
}
/** /**
* return length of received data (without trailing zero) * return length of received data (without trailing zero)
*/ */

View File

@ -23,6 +23,7 @@
// input buffers size // input buffers size
#define UARTBUFSZ (80) #define UARTBUFSZ (80)
void usart_rstbuf();
void usart_setup(); void usart_setup();
void usart_deinit(); void usart_deinit();
int usart_getline(char **line); int usart_getline(char **line);

View File

@ -1,2 +1,2 @@
#define BUILD_NUMBER "84" #define BUILD_NUMBER "93"
#define BUILD_DATE "2024-03-08" #define BUILD_DATE "2024-03-17"