loopback CAN mode

This commit is contained in:
eddyem 2018-06-21 16:04:44 +03:00
parent 7a69f7b3e7
commit 9d9536eb2b
32 changed files with 24133 additions and 2 deletions

View File

@ -4,6 +4,7 @@ Samples for STM32F042-nucleo and chinese STM32F030-based devboard
This directory contains examples for F0 without any library This directory contains examples for F0 without any library
- blink - simple LED blink - blink - simple LED blink
- canbus - CAN bus on STM32F042C6T6
- htu21d_nucleo - operaing with HTU-21D in STM32F042-nucleo - htu21d_nucleo - operaing with HTU-21D in STM32F042-nucleo
- morze - for STM32F030, echo data from USART1 on TIM3CH1 (PA6) as Morze code - morze - for STM32F030, echo data from USART1 on TIM3CH1 (PA6) as Morze code
- tsys01_nucleo - read two TSYS01 sensors using STM32F042 - tsys01_nucleo - read two TSYS01 sensors using STM32F042

View File

@ -0,0 +1,22 @@
EESchema-LIBRARY Version 2.3 Date: Sun 04 May 2014 09:27:50 PM MSK
#encoding utf-8
#
# ACS712
#
DEF ACS712 U 0 40 Y Y 1 F N
F0 "U" 0 300 60 H V C CNN
F1 "ACS712" 0 -350 60 H V C CNN
DRAW
S -450 250 450 -300 0 1 0 N
X IP+ 1 -550 150 300 R 50 50 1 1 I
X IP+ 2 -550 50 300 R 50 50 1 1 I
X IP- 3 -550 -100 300 R 50 50 1 1 I
X IP- 4 -550 -200 300 R 50 50 1 1 I
X GND 5 550 -200 300 L 50 50 1 1 I
X FILTER 6 550 -100 300 L 50 50 1 1 I
X VIOUT 7 550 50 300 L 50 50 1 1 I
X Vcc 8 550 150 300 L 50 50 1 1 I
ENDDRAW
ENDDEF
#
#End Library

View File

@ -0,0 +1,63 @@
[BOM_OPTIONS]
; General BoM options here
; If 'ignore_dnf' option is set to 1, rows that are not to be fitted on the PCB will not be written to the BoM file
ignore_dnf = 1
; If 'number_rows' option is set to 1, each row in the BoM will be prepended with an incrementing row number
number_rows = 1
; If 'group_connectors' option is set to 1, connectors with the same footprints will be grouped together, independent of the name of the connector
group_connectors = 1
; If 'test_regex' option is set to 1, each component group will be tested against a number of regular-expressions (specified, per column, below). If any matches are found, the row is ignored in the output file
test_regex = 1
; If 'merge_blank_fields' option is set to 1, component groups with blank fields will be merged into the most compatible group, where possible
merge_blank_fields = 1
; Field name used to determine if a particular part is to be fitted
fit_field = Config
[IGNORE_COLUMNS]
; Any column heading that appears here will be excluded from the Generated BoM
; Titles are case-insensitive
Part Lib
Footprint Lib
[GROUP_FIELDS]
; List of fields used for sorting individual components into groups
; Components which match (comparing *all* fields) will be grouped together
; Field names are case-insensitive
Part
Part Lib
Value
Footprint
Footprint Lib
[COMPONENT_ALIASES]
; A series of values which are considered to be equivalent for the part name
; Each line represents a tab-separated list of equivalent component name values
; e.g. 'c c_small cap' will ensure the equivalent capacitor symbols can be grouped together
; Aliases are case-insensitive
c c_small cap capacitor
r r_small res resistor
sw switch
l l_small inductor
zener zenersmall
d diode d_small
[REGEX_INCLUDE]
; A series of regular expressions used to include parts in the BoM
; If there are any regex defined here, only components that match against ANY of them will be included in the BOM
; Column names are case-insensitive
; Format is: "ColumName Regex" (tab-separated)
[REGEX_EXCLUDE]
; A series of regular expressions used to exclude parts from the BoM
; If a component matches ANY of these, it will be excluded from the BoM
; Column names are case-insensitive
; Format is: "ColumName Regex" (tab-separated)
References ^TP[0-9]*
References ^FID
Part mount.*hole
Part solder.*bridge
Part test.*point
Footprint test.*point
Footprint mount.*hole
Footprint fiducial

View File

@ -0,0 +1,190 @@
EESchema-LIBRARY Version 2.3
#encoding utf-8
#
# 74HC4051
#
DEF 74HC4051 U 0 10 Y Y 1 F N
F0 "U" 0 0 50 H V C CNN
F1 "74HC4051" 0 -150 50 H V C CNN
F2 "" 0 0 50 H V C CNN
F3 "" 0 0 50 H V C CNN
$FPLIST
SO16
TSSOP16
SSOP16
DHVQFN16
$ENDFPLIST
DRAW
S -400 450 400 -450 0 1 0 N
X Y4 1 700 -50 300 L 50 50 1 1 B
X Y6 2 700 -250 300 L 50 50 1 1 B
X Z 3 0 -750 300 U 50 50 1 1 B
X Y7 4 700 -350 300 L 50 50 1 1 B
X Y5 5 700 -150 300 L 50 50 1 1 B
X ~E 6 -700 -350 300 R 50 50 1 1 I I
X VEE 7 -700 0 300 R 50 50 1 1 W
X GND 8 -700 -200 300 R 50 50 1 1 W
X S2 9 -700 150 300 R 50 50 1 1 I
X S1 10 -700 250 300 R 50 50 1 1 I
X S0 11 -700 350 300 R 50 50 1 1 I
X Y3 12 700 50 300 L 50 50 1 1 B
X Y0 13 700 350 300 L 50 50 1 1 B
X Y1 14 700 250 300 L 50 50 1 1 B
X Y2 15 700 150 300 L 50 50 1 1 B
X VCC 16 -700 -100 300 R 50 50 1 1 W
ENDDRAW
ENDDEF
#
# D_Schottky_x2_ACom_AKK
#
DEF D_Schottky_x2_ACom_AKK D 0 30 Y N 1 F N
F0 "D" 50 -100 50 H V C CNN
F1 "D_Schottky_x2_ACom_AKK" 0 100 50 H V C CNN
F2 "" 0 0 50 H V C CNN
F3 "" 0 0 50 H V C CNN
DRAW
P 2 0 1 0 -140 0 150 0 N
P 2 0 1 0 0 0 0 -100 N
P 3 0 1 8 -150 50 -150 -50 -150 -50 N
P 3 0 1 8 150 50 150 -50 150 -50 N
P 4 0 1 8 -150 50 -170 50 -170 40 -170 40 N
P 4 0 1 8 150 -50 170 -50 170 -40 170 -40 N
P 4 0 1 8 150 50 130 50 130 40 130 40 N
P 5 0 1 8 -130 -40 -130 -50 -150 -50 -150 -50 -150 -50 N
P 6 0 1 8 -50 -50 -150 0 -50 50 -50 -50 -50 -50 -50 -50 N
P 6 0 1 8 50 50 150 0 50 -50 50 50 50 50 50 50 N
X A 1 0 -200 100 U 50 50 0 1 P
X K 2 -300 0 150 R 50 50 0 1 P
X K 3 300 0 150 L 50 50 0 1 P
ENDDRAW
ENDDEF
#
# LM1117-ADJ
#
DEF LM1117-ADJ U 0 30 Y Y 1 F N
F0 "U" 100 -250 50 H V C CNN
F1 "LM1117-ADJ" 0 250 50 H V C CNN
F2 "" 0 0 50 H V C CNN
F3 "" 0 0 50 H V C CNN
ALIAS LM1117-1.8 LM1117-2.5 LM1117-3.3 LM1117-5.0
$FPLIST
SOT-223*
TO-263*
TO-252*
$ENDFPLIST
DRAW
S -200 -200 200 200 0 1 10 f
X GND/ADJ 1 0 -300 100 U 50 50 1 1 W
X VO 2 300 0 100 L 50 50 1 1 w
X VI 3 -300 0 100 R 50 50 1 1 W
ENDDRAW
ENDDEF
#
# PESD1CAN
#
DEF PESD1CAN D 0 30 Y N 1 F N
F0 "D" 0 -350 50 H V C CNN
F1 "PESD1CAN" 50 150 50 H V C CNN
F2 "" 0 0 50 H V C CNN
F3 "" 0 0 50 H V C CNN
$FPLIST
SOT23
$ENDFPLIST
DRAW
S -200 100 300 -300 0 1 0 N
P 2 0 1 0 -140 -200 150 -200 N
P 2 0 1 0 -140 0 150 0 N
P 3 0 1 8 -150 -150 -150 -250 -150 -250 N
P 3 0 1 8 -150 50 -150 -50 -150 -50 N
P 3 0 1 8 150 -150 150 -250 150 -250 N
P 3 0 1 8 150 50 150 -50 150 -50 N
P 4 0 1 8 -150 -150 -170 -150 -170 -160 -170 -160 N
P 4 0 1 8 -150 50 -170 50 -170 40 -170 40 N
P 4 0 1 8 150 -250 170 -250 170 -240 170 -240 N
P 4 0 1 8 150 -150 130 -150 130 -160 130 -160 N
P 4 0 1 8 150 -50 170 -50 170 -40 170 -40 N
P 4 0 1 0 150 0 250 0 250 -200 150 -200 N
P 4 0 1 8 150 50 130 50 130 40 130 40 N
P 5 0 1 8 -130 -240 -130 -250 -150 -250 -150 -250 -150 -250 N
P 5 0 1 8 -130 -40 -130 -50 -150 -50 -150 -50 -150 -50 N
P 6 0 1 8 -50 -250 -150 -200 -50 -150 -50 -250 -50 -250 -50 -250 N
P 6 0 1 8 -50 -50 -150 0 -50 50 -50 -50 -50 -50 -50 -50 N
P 6 0 1 8 50 -150 150 -200 50 -250 50 -150 50 -150 50 -150 N
P 6 0 1 8 50 50 150 0 50 -50 50 50 50 50 50 50 N
X K 1 -300 0 150 R 50 50 0 1 P
X K 2 -300 -200 150 R 50 50 0 1 P
X O 3 400 -100 150 L 50 50 0 1 P
ENDDRAW
ENDDEF
#
# TPS2051
#
DEF TPS2051 U 0 40 Y Y 1 F N
F0 "U" 0 -300 60 H V C CNN
F1 "TPS2051" 0 300 60 H V C CNN
F2 "" 0 0 60 H I C CNN
F3 "" 0 0 60 H I C CNN
DRAW
S -250 250 250 -250 0 1 0 N
X GND 1 -450 150 200 R 50 50 1 1 W
X IN 2 -450 50 200 R 50 50 1 1 W
X IN 3 -450 -50 200 R 50 50 1 1 P
X EN 4 -450 -150 200 R 50 50 1 1 I
X ~OC 5 450 -150 200 L 50 50 1 1 O
X OUT 6 450 -50 200 L 50 50 1 1 P
X OUT 7 450 50 200 L 50 50 1 1 P
X OUT 8 450 150 200 L 50 50 1 1 w
ENDDRAW
ENDDEF
#
# USB6B1
#
DEF USB6B1 D 0 30 Y N 1 F N
F0 "D" 0 -450 50 H V C CNN
F1 "USB6B1" 0 400 50 H V C CNN
F2 "" 200 -100 50 V V C CNN
F3 "" 200 -100 50 V V C CNN
$FPLIST
SO8
$ENDFPLIST
DRAW
C -150 -300 7 0 1 0 N
C -150 100 7 0 1 0 N
C -150 300 7 0 1 0 N
C 0 -300 7 0 1 0 N
C 0 -100 7 0 1 0 N
C 0 300 7 0 1 0 N
C 200 -300 7 0 1 0 N
C 200 300 7 0 1 0 N
S -300 -100 300 -100 0 1 0 N
S -300 300 300 300 0 1 0 N
S -200 -150 -100 -150 0 1 0 N
S -200 250 -100 250 0 1 0 N
S -150 300 -150 -300 0 1 0 N
S -50 -150 50 -150 0 1 0 N
S -50 250 50 250 0 1 0 N
S 0 300 0 -300 0 1 0 N
S 200 300 200 -300 0 1 0 N
S 300 -300 -300 -300 0 1 0 N
S 300 100 -300 100 0 1 0 N
P 3 0 1 8 150 50 250 50 250 50 N
P 4 0 1 8 150 50 150 30 160 30 160 30 N
P 4 0 1 8 250 50 250 70 240 70 240 70 N
P 5 0 1 0 -250 350 300 350 300 -350 -250 -350 -250 350 N
P 6 0 1 8 -200 -250 -150 -150 -100 -250 -200 -250 -200 -250 -200 -250 N
P 6 0 1 8 -200 150 -150 250 -100 150 -200 150 -200 150 -200 150 N
P 6 0 1 8 -50 -250 0 -150 50 -250 -50 -250 -50 -250 -50 -250 N
P 6 0 1 8 -50 150 0 250 50 150 -50 150 -50 150 -50 150 N
P 6 0 1 8 150 -50 200 50 250 -50 150 -50 150 -50 150 -50 N
X VCC 1 -500 300 200 R 50 50 1 1 P
X I/O1 2 -500 100 200 R 50 50 1 1 P
X I/O2 3 -500 -100 200 R 50 50 1 1 P
X GND 4 -500 -300 200 R 50 50 1 1 P
X GND 5 500 -300 200 L 50 50 1 1 P
X I/O2 6 500 -100 200 L 50 50 1 1 P
X I/O1 7 500 100 200 L 50 50 1 1 P
X VCC 8 500 300 200 L 50 50 1 1 P
ENDDRAW
ENDDEF
#
#End Library

View File

@ -0,0 +1,3 @@
(fp_lib_table
(lib (name my_footprints)(type KiCad)(uri "$(KIPRJMOD)/my_footprints.pretty")(options "")(descr ""))
)

View File

@ -0,0 +1,9 @@
(module Hole_3mm (layer F.Cu) (tedit 5913F6E4)
(fp_text reference REF** (at 0 3.81) (layer F.SilkS) hide
(effects (font (size 1 1) (thickness 0.15)))
)
(fp_text value Hole_3mm (at 0 -7.62) (layer F.Fab) hide
(effects (font (size 1 1) (thickness 0.15)))
)
(pad 1 thru_hole circle (at 0 0) (size 5 5) (drill 3) (layers *.Cu *.Mask))
)

View File

@ -0,0 +1,31 @@
(module RJ9-4P4C (layer F.Cu) (tedit 555F7A30)
(fp_text reference J** (at 0 -10.1346) (layer F.SilkS)
(effects (font (size 1 1) (thickness 0.15)))
)
(fp_text value RJ9-4P4C (at 0 10.2108) (layer F.Fab) hide
(effects (font (size 1 1) (thickness 0.15)))
)
(fp_circle (center 0 0) (end -0.25 0) (layer F.CrtYd) (width 0.05))
(fp_line (start -5.84 -9.25) (end 5.84 -9.25) (layer F.CrtYd) (width 0.05))
(fp_line (start 5.84 -9.25) (end 5.84 9.25) (layer F.CrtYd) (width 0.05))
(fp_line (start 5.84 9.25) (end -5.84 9.25) (layer F.CrtYd) (width 0.05))
(fp_line (start -5.84 9.25) (end -5.84 -9.25) (layer F.CrtYd) (width 0.05))
(fp_line (start 0 -0.35) (end 0 0.35) (layer F.CrtYd) (width 0.05))
(fp_line (start -0.35 0) (end 0.35 0) (layer F.CrtYd) (width 0.05))
(fp_line (start -5.59 9) (end -5.59 -9) (layer F.Fab) (width 0.12))
(fp_line (start -5.59 -9) (end 5.59 -9) (layer F.Fab) (width 0.12))
(fp_line (start 5.59 -9) (end 5.59 9) (layer F.Fab) (width 0.12))
(fp_line (start 5.59 9) (end -5.59 9) (layer F.Fab) (width 0.12))
(fp_line (start -5.59 8.8) (end -5.59 -9) (layer F.SilkS) (width 0.12))
(fp_line (start -5.59 -9) (end 5.59 -9) (layer F.SilkS) (width 0.12))
(fp_line (start 5.59 -9) (end 5.59 8.8) (layer F.SilkS) (width 0.12))
(fp_circle (center 3.81 1.15) (end 5.75 1.15) (layer B.CrtYd) (width 0.05))
(fp_circle (center -3.81 1.15) (end -5.75 1.15) (layer B.CrtYd) (width 0.05))
(fp_circle (center -1.905 -6.12) (end -1.805 -6.12) (layer F.SilkS) (width 0.2))
(pad 1 thru_hole circle (at -1.905 -5.2) (size 1.2 1.2) (drill 0.8) (layers *.Cu *.Mask))
(pad 2 thru_hole circle (at -0.635 -7.74) (size 1.2 1.2) (drill 0.8) (layers *.Cu *.Mask))
(pad 3 thru_hole circle (at 0.635 -5.2) (size 1.2 1.2) (drill 0.8) (layers *.Cu *.Mask))
(pad 4 thru_hole circle (at 1.905 -7.74) (size 1.2 1.2) (drill 0.8) (layers *.Cu *.Mask))
(pad "" np_thru_hole circle (at -3.81 1.15) (size 3.2 3.2) (drill 3.2) (layers *.Cu *.Mask))
(pad "" np_thru_hole circle (at 3.81 1.15) (size 3.2 3.2) (drill 3.2) (layers *.Cu *.Mask))
)

View File

@ -0,0 +1,12 @@
(module SMD_conn_4x2.5mm (layer F.Cu) (tedit 58B86145)
(fp_text reference REF** (at 0 3.81) (layer F.SilkS)
(effects (font (size 1 1) (thickness 0.15)))
)
(fp_text value SMD_conn_4x2.5mm (at 0 -3.81) (layer F.Fab)
(effects (font (size 1 1) (thickness 0.15)))
)
(pad 1 smd rect (at -3.81 0) (size 1.5 5) (layers F.Cu F.Paste F.Mask))
(pad 2 smd rect (at -1.27 0) (size 1.5 5) (layers F.Cu F.Paste F.Mask))
(pad 3 smd rect (at 1.27 0) (size 1.5 5) (layers F.Cu F.Paste F.Mask))
(pad 4 smd rect (at 3.81 0) (size 1.5 5) (layers F.Cu F.Paste F.Mask))
)

View File

@ -0,0 +1,10 @@
(module TH_via (layer F.Cu) (tedit 5A5E619A)
(fp_text reference REF** (at 0 0.5) (layer F.SilkS) hide
(effects (font (size 1 1) (thickness 0.15)))
)
(fp_text value TH_via (at 0 -0.5) (layer F.Fab) hide
(effects (font (size 1 1) (thickness 0.15)))
)
(pad 1 thru_hole circle (at 0 0) (size 1.5 1.5) (drill 0.8) (layers *.Cu *.Mask)
(zone_connect 1))
)

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 88 KiB

View File

@ -0,0 +1,821 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
width="8.6233cm" height="9.55802cm" viewBox="0 0 33950 37630 ">
<title>SVG Picture created as stm32-B.SilkS.svg date 2018/06/18 13:58:33 </title>
<desc>Picture generated by PCBNEW </desc>
<g style="fill:#000000; fill-opacity:1;stroke:#000000; stroke-opacity:1;
stroke-linecap:round; stroke-linejoin:round; "
transform="translate(0 0) scale(1 1)">
</g>
<g style="fill:#000000; fill-opacity:0.0;
stroke:#000000; stroke-width:-0.000393701; stroke-opacity:1;
stroke-linecap:round; stroke-linejoin:round;">
</g>
<g style="fill:#000000; fill-opacity:0.0;
stroke:#000000; stroke-width:59.0551; stroke-opacity:1;
stroke-linecap:round; stroke-linejoin:round;">
<path d="M30252 1927
L4661 1927
" />
<path d="M30252 34998
L30252 1927
" />
<path d="M4661 34998
L30252 34998
" />
<path d="M4661 1927
L4661 34998
" />
<path d="M20256 14138
L20256 13744
L20349 13744
L20406 13763
L20443 13800
L20462 13838
L20481 13913
L20481 13969
L20462 14044
L20443 14082
L20406 14119
L20349 14138
L20256 14138
" />
<path d="M20612 13744
L20856 13744
L20724 13894
L20781 13894
L20818 13913
L20837 13932
L20856 13969
L20856 14063
L20837 14100
L20818 14119
L20781 14138
L20668 14138
L20631 14119
L20612 14100
" />
<path d="M21657 26111
L21619 26092
L21582 26055
L21526 25998
L21488 25980
L21451 25980
" />
<path d="M21469 26073
L21432 26055
L21394 26017
L21376 25942
L21376 25811
L21394 25736
L21432 25698
L21469 25680
L21544 25680
L21582 25698
L21619 25736
L21638 25811
L21638 25942
L21619 26017
L21582 26055
L21544 26073
L21469 26073
" />
<path d="M22013 26073
L21788 26073
" />
<path d="M21901 26073
L21901 25680
L21863 25736
L21826 25773
L21788 25792
" />
<path d="M18229 30006
L18098 29818
" />
<path d="M18004 30006
L18004 29612
L18154 29612
L18191 29631
L18210 29649
L18229 29687
L18229 29743
L18210 29781
L18191 29799
L18154 29818
L18004 29818
" />
<path d="M18360 29612
L18604 29612
L18472 29762
L18529 29762
L18566 29781
L18585 29799
L18604 29837
L18604 29931
L18585 29968
L18566 29987
L18529 30006
L18416 30006
L18379 29987
L18360 29968
" />
<path d="M16341 30014
L16210 29826
" />
<path d="M16116 30014
L16116 29620
L16266 29620
L16303 29639
L16322 29657
L16341 29695
L16341 29751
L16322 29789
L16303 29807
L16266 29826
L16116 29826
" />
<path d="M16678 29751
L16678 30014
" />
<path d="M16584 29601
L16491 29882
L16734 29882
" />
<path d="M18304 31439
L18173 31251
" />
<path d="M18079 31439
L18079 31045
L18229 31045
L18266 31064
L18285 31082
L18304 31120
L18304 31176
L18285 31214
L18266 31232
L18229 31251
L18079 31251
" />
<path d="M18641 31045
L18566 31045
L18529 31064
L18510 31082
L18472 31139
L18454 31214
L18454 31364
L18472 31401
L18491 31420
L18529 31439
L18604 31439
L18641 31420
L18660 31401
L18679 31364
L18679 31270
L18660 31232
L18641 31214
L18604 31195
L18529 31195
L18491 31214
L18472 31232
L18454 31270
" />
<path d="M17528 30878
L17716 30747
" />
<path d="M17528 30653
L17922 30653
L17922 30803
L17903 30840
L17885 30859
L17847 30878
L17791 30878
L17753 30859
L17735 30840
L17716 30803
L17716 30653
" />
<path d="M17922 31009
L17922 31272
L17528 31103
" />
<path d="M21768 14564
L21956 14433
" />
<path d="M21768 14339
L22162 14339
L22162 14489
L22143 14526
L22124 14545
L22087 14564
L22031 14564
L21993 14545
L21974 14526
L21956 14489
L21956 14339
" />
<path d="M21768 14751
L21768 14826
L21787 14864
L21806 14883
L21862 14920
L21937 14939
L22087 14939
L22124 14920
L22143 14901
L22162 14864
L22162 14789
L22143 14751
L22124 14733
L22087 14714
L21993 14714
L21956 14733
L21937 14751
L21918 14789
L21918 14864
L21937 14901
L21956 14920
L21993 14939
" />
<path d="M19262 26626
L19243 26608
L19224 26551
L19224 26514
L19243 26458
L19280 26420
L19318 26401
L19393 26383
L19449 26383
L19524 26401
L19562 26420
L19599 26458
L19618 26514
L19618 26551
L19599 26608
L19580 26626
" />
<path d="M19224 27001
L19224 26776
" />
<path d="M19224 26889
L19618 26889
L19562 26851
L19524 26814
L19505 26776
" />
<path d="M19618 27357
L19618 27170
L19430 27151
L19449 27170
L19468 27208
L19468 27301
L19449 27339
L19430 27357
L19393 27376
L19299 27376
L19262 27357
L19243 27339
L19224 27301
L19224 27208
L19243 27170
L19262 27151
" />
<path d="M21129 32678
L21110 32697
L21054 32715
L21016 32715
L20960 32697
L20923 32659
L20904 32622
L20885 32547
L20885 32490
L20904 32415
L20923 32378
L20960 32340
L21016 32322
L21054 32322
L21110 32340
L21129 32359
" />
<path d="M21504 32715
L21279 32715
" />
<path d="M21391 32715
L21391 32322
L21354 32378
L21316 32415
L21279 32434
" />
<path d="M8307 12979
L8269 12961
L8232 12923
L8176 12867
L8138 12848
L8101 12848
" />
<path d="M8119 12942
L8082 12923
L8044 12886
L8026 12811
L8026 12679
L8044 12604
L8082 12567
L8119 12548
L8194 12548
L8232 12567
L8269 12604
L8288 12679
L8288 12811
L8269 12886
L8232 12923
L8194 12942
L8119 12942
" />
<path d="M8438 12586
L8457 12567
L8494 12548
L8588 12548
L8626 12567
L8644 12586
L8663 12623
L8663 12661
L8644 12717
L8419 12942
L8663 12942
" />
<path d="M9263 15692
L9282 15654
L9319 15617
L9376 15561
L9394 15523
L9394 15486
" />
<path d="M9301 15504
L9319 15467
L9357 15429
L9432 15411
L9563 15411
L9638 15429
L9675 15467
L9694 15504
L9694 15579
L9675 15617
L9638 15654
L9563 15673
L9432 15673
L9357 15654
L9319 15617
L9301 15579
L9301 15504
" />
<path d="M9694 15804
L9694 16048
L9544 15917
L9544 15973
L9526 16011
L9507 16029
L9469 16048
L9376 16048
L9338 16029
L9319 16011
L9301 15973
L9301 15861
L9319 15823
L9338 15804
" />
<path d="M9263 18942
L9282 18904
L9319 18867
L9376 18811
L9394 18773
L9394 18736
" />
<path d="M9301 18754
L9319 18717
L9357 18679
L9432 18661
L9563 18661
L9638 18679
L9675 18717
L9694 18754
L9694 18829
L9675 18867
L9638 18904
L9563 18923
L9432 18923
L9357 18904
L9319 18867
L9301 18829
L9301 18754
" />
<path d="M9563 19261
L9301 19261
" />
<path d="M9713 19167
L9432 19073
L9432 19317
" />
<path d="M8391 22678
L8260 22491
" />
<path d="M8166 22678
L8166 22285
L8316 22285
L8354 22303
L8373 22322
L8391 22360
L8391 22416
L8373 22453
L8354 22472
L8316 22491
L8166 22491
" />
<path d="M8766 22678
L8541 22678
" />
<path d="M8654 22678
L8654 22285
L8616 22341
L8579 22378
L8541 22397
" />
<path d="M9141 22678
L8916 22678
" />
<path d="M9029 22678
L9029 22285
L8991 22341
L8954 22378
L8916 22397
" />
<path d="M8391 23378
L8260 23191
" />
<path d="M8166 23378
L8166 22985
L8316 22985
L8354 23003
L8373 23022
L8391 23060
L8391 23116
L8373 23153
L8354 23172
L8316 23191
L8166 23191
" />
<path d="M8766 23378
L8541 23378
" />
<path d="M8654 23378
L8654 22985
L8616 23041
L8579 23078
L8541 23097
" />
<path d="M8916 23022
L8935 23003
L8972 22985
L9066 22985
L9104 23003
L9122 23022
L9141 23060
L9141 23097
L9122 23153
L8897 23378
L9141 23378
" />
<path d="M22782 30029
L22463 30029
L22425 30048
L22407 30067
L22388 30104
L22388 30179
L22407 30217
L22425 30236
L22463 30254
L22782 30254
" />
<path d="M22388 30648
L22388 30423
" />
<path d="M22388 30536
L22782 30536
L22725 30498
L22688 30461
L22669 30423
" />
<path d="M12451 22589
L12844 22589
L12844 22683
L12825 22739
L12788 22776
L12750 22795
L12676 22814
L12619 22814
L12544 22795
L12507 22776
L12469 22739
L12451 22683
L12451 22589
" />
<path d="M12451 23189
L12451 22964
" />
<path d="M12451 23076
L12844 23076
L12788 23039
L12750 23001
L12732 22964
" />
<path d="M21891 16777
L21760 16589
" />
<path d="M21666 16777
L21666 16383
L21816 16383
L21854 16402
L21873 16421
L21891 16458
L21891 16514
L21873 16552
L21854 16571
L21816 16589
L21666 16589
" />
<path d="M22266 16777
L22041 16777
" />
<path d="M22154 16777
L22154 16383
L22116 16439
L22079 16477
L22041 16496
" />
<path d="M22604 16514
L22604 16777
" />
<path d="M22510 16364
L22416 16646
L22660 16646
" />
<path d="M16604 28992
L16604 28598
L16698 28598
L16754 28617
L16791 28654
L16810 28692
L16829 28767
L16829 28823
L16810 28898
L16791 28936
L16754 28973
L16698 28992
L16604 28992
" />
<path d="M17054 28767
L17016 28748
L16997 28729
L16979 28692
L16979 28673
L16997 28636
L17016 28617
L17054 28598
L17129 28598
L17166 28617
L17185 28636
L17204 28673
L17204 28692
L17185 28729
L17166 28748
L17129 28767
L17054 28767
L17016 28786
L16997 28804
L16979 28842
L16979 28917
L16997 28954
L17016 28973
L17054 28992
L17129 28992
L17166 28973
L17185 28954
L17204 28917
L17204 28842
L17185 28804
L17166 28786
L17129 28767
" />
<path d="M15051 31739
L15444 31739
L15444 31833
L15425 31889
L15388 31926
L15350 31945
L15276 31964
L15219 31964
L15144 31945
L15107 31926
L15069 31889
L15051 31833
L15051 31739
" />
<path d="M15051 32151
L15051 32226
L15069 32264
L15088 32283
L15144 32320
L15219 32339
L15369 32339
L15407 32320
L15425 32301
L15444 32264
L15444 32189
L15425 32151
L15407 32133
L15369 32114
L15276 32114
L15238 32133
L15219 32151
L15201 32189
L15201 32264
L15219 32301
L15238 32320
L15276 32339
" />
</g>
<g style="fill:#000000; fill-opacity:0.0;
stroke:#000000; stroke-width:47.2441; stroke-opacity:1;
stroke-linecap:round; stroke-linejoin:round;">
<path d="M20095 14907
L20095 15274
" />
<path d="M20095 16151
L20095 15785
" />
<path d="M20095 16151
L20946 16151
" />
<path d="M20095 14907
L20670 14907
" />
<path d="M21994 27501
L21994 27135
" />
<path d="M21994 26257
L21994 26624
" />
<path d="M21994 26257
L20749 26257
" />
<path d="M21994 27501
L21419 27501
" />
</g>
<g style="fill:#000000; fill-opacity:0.0;
stroke:#000000; stroke-width:59.0551; stroke-opacity:1;
stroke-linecap:round; stroke-linejoin:round;">
<path d="M18098 28814
L18491 28814
" />
<path d="M18491 29345
L18098 29345
" />
<path d="M16210 28822
L16603 28822
" />
<path d="M16603 29353
L16210 29353
" />
<path d="M18173 30247
L18566 30247
" />
<path d="M18566 30778
L18173 30778
" />
<path d="M16693 31140
L16693 30747
" />
<path d="M17224 30747
L17224 31140
" />
<path d="M22960 14433
L22960 14826
" />
<path d="M22429 14826
L22429 14433
" />
</g>
<g style="fill:#000000; fill-opacity:0.0;
stroke:#000000; stroke-width:47.2441; stroke-opacity:1;
stroke-linecap:round; stroke-linejoin:round;">
<path d="M19658 27017
L19658 26742
" />
<path d="M20131 26742
L20131 27017
" />
<path d="M21057 32793
L21332 32793
" />
<path d="M21332 33266
L21057 33266
" />
<path d="M8045 11157
L8045 11524
" />
<path d="M8045 12401
L8045 12035
" />
<path d="M8045 12401
L9289 12401
" />
<path d="M8045 11157
L8620 11157
" />
<path d="M7872 16029
L8238 16029
" />
<path d="M9116 16029
L8750 16029
" />
<path d="M9116 16029
L9116 14785
" />
<path d="M7872 16029
L7872 15454
" />
<path d="M7872 19279
L8238 19279
" />
<path d="M9116 19279
L8750 19279
" />
<path d="M9116 19279
L9116 18035
" />
<path d="M7872 19279
L7872 18704
" />
<path d="M8448 21662
L8841 21662
" />
<path d="M8841 22197
L8448 22197
" />
<path d="M8448 22362
L8841 22362
" />
<path d="M8841 22897
L8448 22897
" />
<path d="M19452 31081
L19948 31081
" />
<path d="M22137 31081
L21641 31081
" />
<path d="M19452 29601
L19452 31081
" />
<path d="M22137 28715
L22137 31081
" />
<path d="M11022 23179
L11388 23179
" />
<path d="M12266 23179
L11900 23179
" />
<path d="M12266 23179
L12266 22328
" />
<path d="M11022 23179
L11022 22604
" />
<path d="M21908 15583
L22381 15583
" />
<path d="M22381 16276
L21908 16276
" />
<path d="M18233 28479
L18233 27180
" />
<path d="M18233 27180
L16107 27180
" />
<path d="M18233 28479
L16107 28479
" />
<path d="M14894 30691
L13595 30691
" />
<path d="M13595 30691
L13595 32817
" />
<path d="M14894 30691
L14894 32817
" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 121 KiB

View File

@ -0,0 +1,45 @@
EESchema-LIBRARY Version 2.3
#encoding utf-8
#
# LM1117-3.3-RESCUE-stm32
#
DEF LM1117-3.3-RESCUE-stm32 U 0 30 Y Y 1 F N
F0 "U" 100 -250 50 H V C CNN
F1 "LM1117-3.3-RESCUE-stm32" 0 250 50 H V C CNN
F2 "" 0 0 50 H I C CNN
F3 "" 0 0 50 H I C CNN
$FPLIST
SOT-223*
TO-263*
TO-252*
$ENDFPLIST
DRAW
S -200 -200 200 200 0 1 10 f
X GND/ADJ 1 0 -300 100 U 50 50 1 1 W
X VO 2 300 50 100 L 50 50 1 1 P
X VI 3 -300 0 100 R 50 50 1 1 W
X VO 4 300 -50 100 L 50 50 1 1 w
ENDDRAW
ENDDEF
#
# MAX471-RESCUE-stm32
#
DEF MAX471-RESCUE-stm32 U 0 40 Y Y 1 F N
F0 "U" -300 350 50 H V L CNN
F1 "MAX471-RESCUE-stm32" -300 -350 50 H V L CNN
F2 "" 0 0 50 H I C CNN
F3 "" 0 0 50 H I C CNN
DRAW
S -300 300 300 -300 0 1 10 f
X SHDN 1 -400 -100 100 R 50 50 1 1 I
X RS+ 2 -400 200 100 R 50 50 1 1 W
X RS+ 3 -400 100 100 R 50 50 1 1 P
X GND 4 -400 -200 100 R 50 50 1 1 W
X SIGN 5 400 -100 100 L 50 50 1 1 C
X RS- 6 400 200 100 L 50 50 1 1 w
X RS- 7 400 100 100 L 50 50 1 1 P
X OUT 8 400 -200 100 L 50 50 1 1 O
ENDDRAW
ENDDEF
#
#End Library

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,67 @@
update=Чт 11 янв 2018 23:12:54
version=1
last_client=kicad
[pcbnew]
version=1
LastNetListRead=
UseCmpFile=1
PadDrill=0.600000000000
PadDrillOvalY=0.600000000000
PadSizeH=1.500000000000
PadSizeV=1.500000000000
PcbTextSizeV=1.500000000000
PcbTextSizeH=1.500000000000
PcbTextThickness=0.300000000000
ModuleTextSizeV=1.000000000000
ModuleTextSizeH=1.000000000000
ModuleTextSizeThickness=0.150000000000
SolderMaskClearance=0.000000000000
SolderMaskMinWidth=0.000000000000
DrawSegmentWidth=0.200000000000
BoardOutlineThickness=0.100000000000
ModuleOutlineThickness=0.150000000000
[cvpcb]
version=1
NetIExt=net
[general]
version=1
[eeschema]
version=1
LibDir=/home/eddy/kicad/Kicad-Libraries/library
[eeschema/libraries]
LibName1=stm32-rescue
LibName2=power
LibName3=device
LibName4=transistors
LibName5=conn
LibName6=linear
LibName7=regul
LibName8=74xx
LibName9=cmos4000
LibName10=adc-dac
LibName11=memory
LibName12=xilinx
LibName13=microcontrollers
LibName14=dsp
LibName15=microchip
LibName16=analog_switches
LibName17=motorola
LibName18=texas
LibName19=intel
LibName20=audio
LibName21=interface
LibName22=digital-audio
LibName23=philips
LibName24=display
LibName25=cypress
LibName26=siliconi
LibName27=opto
LibName28=atmel
LibName29=contrib
LibName30=valves
LibName31=stm32
LibName32=vreg
LibName33=elements
LibName34=ESD_Protection
LibName35=switches
LibName36=acs712

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,32 @@
[editor]
line_wrapping=false
line_break_column=100
auto_continue_multiline=true
[file_prefs]
final_new_line=true
ensure_convert_new_lines=true
strip_trailing_spaces=true
replace_tabs=true
[indentation]
indent_width=4
indent_type=0
indent_hard_tab_width=4
detect_indent=false
detect_indent_width=false
indent_mode=3
[project]
name=CANbus
base_path=/home/eddy/Docs/SAO/ELECTRONICS/STM32/F0-srcs/canbus/src
[long line marker]
long_line_behaviour=1
long_line_column=100
[files]
current_page=-1
[VTE]
last_dir=/home/eddy

View File

@ -0,0 +1,145 @@
BINARY = canbus
BOOTPORT ?= /dev/ttyUSB0
BOOTSPEED ?= 57600
# MCU FAMILY
FAMILY = F0
# MCU code
MCU = F042x6
# hardware definitions
DEFS += -DUSARTNUM=1
#DEFS += -DCHECK_TMOUT
#DEFS += -DEBUG
# change this linking script depending on particular MCU model,
# for example, if you have STM32F103VBT6, you should write:
LDSCRIPT = ld/stm32f042k.ld
INDEPENDENT_HEADERS=
FP_FLAGS ?= -msoft-float
ASM_FLAGS = -mthumb -mcpu=cortex-m0 -march=armv6-m -mtune=cortex-m0
ARCH_FLAGS = $(ASM_FLAGS) $(FP_FLAGS)
###############################################################################
# Executables
OPREFIX ?= /opt/bin/arm-none-eabi
#PREFIX ?= /usr/x86_64-pc-linux-gnu/arm-none-eabi/gcc-bin/7.3.0/arm-none-eabi
PREFIX ?= $(OPREFIX)
RM := rm -f
RMDIR := rmdir
CC := $(PREFIX)-gcc
LD := $(PREFIX)-gcc
AR := $(PREFIX)-ar
AS := $(PREFIX)-as
OBJCOPY := $(OPREFIX)-objcopy
OBJDUMP := $(OPREFIX)-objdump
GDB := $(OPREFIX)-gdb
STFLASH := $(shell which st-flash)
STBOOT := $(shell which stm32flash)
###############################################################################
# Source files
OBJDIR = mk
LDSCRIPT ?= $(BINARY).ld
SRC := $(wildcard *.c)
OBJS := $(addprefix $(OBJDIR)/, $(SRC:%.c=%.o))
STARTUP = $(OBJDIR)/startup.o
OBJS += $(STARTUP)
DEPS := $(OBJS:.o=.d)
INC_DIR ?= ../../inc
INCLUDE := -I$(INC_DIR)/F0 -I$(INC_DIR)/cm
LIB_DIR := $(INC_DIR)/ld
###############################################################################
# C flags
CFLAGS += -O2 -g -MD -D__thumb2__=1
CFLAGS += -Wall -Wextra -Wshadow -Wimplicit-function-declaration
CFLAGS += -Wredundant-decls $(INCLUDE)
# -Wmissing-prototypes -Wstrict-prototypes
CFLAGS += -fno-common -ffunction-sections -fdata-sections
###############################################################################
# Linker flags
LDFLAGS += --static -nostartfiles
#--specs=nano.specs
LDFLAGS += -L$(LIB_DIR)
LDFLAGS += -T$(LDSCRIPT)
LDFLAGS += -Wl,-Map=$(OBJDIR)/$(BINARY).map
LDFLAGS += -Wl,--gc-sections
###############################################################################
# Used libraries
LDLIBS += -Wl,--start-group -lc -lgcc -Wl,--end-group
LDLIBS += $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
DEFS += -DSTM32$(FAMILY) -DSTM32$(MCU)
#.SUFFIXES: .elf .bin .hex .srec .list .map .images
#.SECONDEXPANSION:
#.SECONDARY:
ELF := $(OBJDIR)/$(BINARY).elf
LIST := $(OBJDIR)/$(BINARY).list
BIN := $(BINARY).bin
HEX := $(BINARY).hex
all: bin list
elf: $(ELF)
bin: $(BIN)
hex: $(HEX)
list: $(LIST)
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif
$(OBJDIR):
mkdir $(OBJDIR)
$(STARTUP): $(INC_DIR)/startup/vector.c
$(CC) $(CFLAGS) $(DEFS) $(INCLUDE) $(ARCH_FLAGS) -o $@ -c $<
$(OBJDIR)/%.o: %.c
@echo " CC $<"
$(CC) $(CFLAGS) $(DEFS) $(INCLUDE) $(ARCH_FLAGS) -o $@ -c $<
#$(OBJDIR)/%.d: %.c $(OBJDIR)
# $(CC) -MM -MG $< | sed -e 's,^\([^:]*\)\.o[ ]*:,$(@D)/\1.o $(@D)/\1.d:,' >$@
$(BIN): $(ELF)
@echo " OBJCOPY $(BIN)"
$(OBJCOPY) -Obinary $(ELF) $(BIN)
$(HEX): $(ELF)
@echo " OBJCOPY $(HEX)"
$(OBJCOPY) -Oihex $(ELF) $(HEX)
$(LIST): $(ELF)
@echo " OBJDUMP $(LIST)"
$(OBJDUMP) -S $(ELF) > $(LIST)
$(ELF): $(OBJDIR) $(OBJS)
@echo " LD $(ELF)"
$(LD) $(LDFLAGS) $(ARCH_FLAGS) $(OBJS) $(LDLIBS) -o $(ELF)
clean:
@echo " CLEAN"
$(RM) $(OBJS) $(DEPS) $(ELF) $(HEX) $(LIST) $(OBJDIR)/*.map *.d
@rmdir $(OBJDIR) 2>/dev/null || true
flash: $(BIN)
@echo " FLASH $(BIN)"
$(STFLASH) write $(BIN) 0x8000000
boot: $(BIN)
@echo " LOAD $(BIN) through bootloader"
$(STBOOT) -b$(BOOTSPEED) $(BOOTPORT) -w $(BIN)
gentags:
CFLAGS="$(CFLAGS) $(DEFS)" geany -g $(BINARY).c.tags *[hc] 2>/dev/null
.PHONY: clean flash boot gentags

131
F0-nolib/canbus/src/can.c Normal file
View File

@ -0,0 +1,131 @@
/*
* geany_encoding=koi8-r
* can.c
*
* Copyright 2018 Edward V. Emelianov <eddy@sao.ru, edward.emelianoff@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#include "can.h"
#include "hardware.h"
#include "usart.h"
#define CMD_TOGGLE (0xDA)
#define CAN_ID_MASK (0xFF70U)
#define CAN_ID1 (0x651U)
#define CAN_ID2 (0x652U)
#define FILTER_LIST (0) /* 0: filter mode = identifier mask, 1: filter mode = identifier list */
#define CAN_FLAG_GOTDUMMY (1)
static uint8_t CAN_addr = 255;
static uint8_t CAN_flags = 0;
// get CAN address data from GPIO pins
void readCANaddr(){
CAN_addr = READ_CAN_INV_ADDR();
CAN_addr = ~CAN_addr & 0x7;
}
uint8_t getCANaddr(){
return CAN_addr;
}
void CAN_setup(){
if(CAN_addr == 255) readCANaddr();
// Configure GPIO: PB8 - CAN_Rx, PB9 - CAN_Tx
/* (1) Select AF mode (10) on PB8 and PB9 */
/* (2) AF4 for CAN signals */
GPIOB->MODER = (GPIOB->MODER & ~(GPIO_MODER_MODER8 | GPIO_MODER_MODER9))
| (GPIO_MODER_MODER8_AF | GPIO_MODER_MODER9_AF); /* (1) */
GPIOB->AFR[1] = (GPIOB->AFR[1] &~ (GPIO_AFRH_AFRH0 | GPIO_AFRH_AFRH1))\
| (4 << (0 * 4)) | (4 << (1 * 4)); /* (2) */
/* Enable the peripheral clock CAN */
RCC->APB1ENR |= RCC_APB1ENR_CANEN;
/* Configure CAN */
/* (1) Enter CAN init mode to write the configuration */
/* (2) Wait the init mode entering */
/* (3) Exit sleep mode */
/* (4) Loopback mode, set timing to 1Mb/s: BS1 = 4, BS2 = 3, prescaler = 6 */
/* (5) Leave init mode */
/* (6) Wait the init mode leaving */
/* (7) Enter filter init mode, (16-bit + mask, filter 0 for FIFO 0) */
/* (8) Acivate filter 0 */
/* (9) Identifier list mode */
/* (11) Set the Id list */
/* (12) Set the Id + mask (all bits of standard id will care) */
/* (13) Leave filter init */
/* (14) Set FIFO0 message pending IT enable */
CAN->MCR |= CAN_MCR_INRQ; /* (1) */
while((CAN->MSR & CAN_MSR_INAK)!=CAN_MSR_INAK) /* (2) */
{
/* add time out here for a robust application */
}
CAN->MCR &=~ CAN_MCR_SLEEP; /* (3) */
CAN->BTR |= CAN_BTR_LBKM | 2 << 20 | 3 << 16 | 5 << 0; /* (4) */
CAN->MCR &=~ CAN_MCR_INRQ; /* (5) */
while((CAN->MSR & CAN_MSR_INAK)==CAN_MSR_INAK) /* (6) */
{
/* add time out here for a robust application */
}
CAN->FMR = CAN_FMR_FINIT; /* (7) */
CAN->FA1R = CAN_FA1R_FACT0; /* (8) */
#if (FILTER_LIST)
CAN->FM1R = CAN_FM1R_FBM0; /* (9) */
CAN->sFilterRegister[0].FR1 = CAN_ID2 << 5 | CAN_ID1 << (16+5); /* (10) */
#else
CAN->sFilterRegister[0].FR1 = CAN_ID1 << 5 | CAN_ID_MASK << 16; /* (11) */
#endif /* FILTER_LIST */
CAN->FMR &=~ CAN_FMR_FINIT; /* (12) */
CAN->IER |= CAN_IER_FMPIE0; /* (13) */
/* Configure IT */
/* (14) Set priority for CAN_IRQn */
/* (15) Enable CAN_IRQn */
NVIC_SetPriority(CEC_CAN_IRQn, 0); /* (16) */
NVIC_EnableIRQ(CEC_CAN_IRQn); /* (17) */
}
void can_proc(){
if(CAN_flags){
if(CAN_flags & CAN_FLAG_GOTDUMMY){
SEND("Got dummy message\n");
}
CAN_flags = 0;
}
}
void can_send_dummy(){
if((CAN->TSR & CAN_TSR_TME0) == CAN_TSR_TME0){ /* check mailbox 0 is empty */
CAN->sTxMailBox[0].TDTR = 1; /* fill data length = 1 */
CAN->sTxMailBox[0].TDLR = CMD_TOGGLE; /* fill 8-bit data */
CAN->sTxMailBox[0].TIR = (uint32_t)(CAN_ID1 << 21 | CAN_TI0R_TXRQ); /* fill Id field and request a transmission */
}
}
void cec_can_isr(){
uint32_t CAN_ReceiveMessage = 0;
if(CAN->RF0R & CAN_RF0R_FMP0){ /* check if a message is filtered and received by FIFO 0 */
LED_blink(LED1); /* Toggle LED1 */
CAN_ReceiveMessage = CAN->sFIFOMailBox[0].RDLR; /* read data */
CAN->RF0R |= CAN_RF0R_RFOM0; /* release FIFO */
if((CAN_ReceiveMessage & 0xFF) == CMD_TOGGLE){
CAN_flags |= CAN_FLAG_GOTDUMMY;
}
}
}

37
F0-nolib/canbus/src/can.h Normal file
View File

@ -0,0 +1,37 @@
/*
* geany_encoding=koi8-r
* can.h
*
* Copyright 2018 Edward V. Emelianov <eddy@sao.ru, edward.emelianoff@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#pragma once
#ifndef __CAN_H__
#define __CAN_H__
#include "hardware.h"
void readCANaddr();
uint8_t getCANaddr();
void CAN_setup();
void can_send_dummy();
void can_proc();
#endif // __CAN_H__

BIN
F0-nolib/canbus/src/canbus.bin Executable file

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,43 @@
/*
* geany_encoding=koi8-r
* hardware.c - hardware-dependent macros & functions
*
* Copyright 2018 Edward V. Emelianov <eddy@sao.ru, edward.emelianoff@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#include "hardware.h"
#include "usart.h"
void gpio_setup(void){
// here we turn on clocking for all periph.
RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN | RCC_AHBENR_GPIOCEN | RCC_AHBENR_DMAEN;
// Set LEDS (PC13/14) as output
GPIOC->MODER = (GPIOC->MODER & ~(GPIO_MODER_MODER13 | GPIO_MODER_MODER14)
) |
GPIO_MODER_MODER13_O | GPIO_MODER_MODER14_O;
// PB14(0), PB15(1), PA8(2) - CAN address, pullup inputs
GPIOA->PUPDR = (GPIOA->PUPDR & ~(GPIO_PUPDR_PUPDR8)
) |
GPIO_PUPDR_PUPDR8_0;
GPIOB->PUPDR = (GPIOB->PUPDR & ~(GPIO_PUPDR_PUPDR14 | GPIO_PUPDR_PUPDR15)
) |
GPIO_PUPDR_PUPDR14_0 | GPIO_PUPDR_PUPDR15_0;
pin_set(LED0_port, LED0_pin); // clear LEDs
pin_set(LED1_port, LED1_pin);
}

View File

@ -0,0 +1,52 @@
/*
* geany_encoding=koi8-r
* hardware.h
*
* Copyright 2018 Edward V. Emelianov <eddy@sao.ru, edward.emelianoff@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#pragma once
#ifndef __HARDWARE_H__
#define __HARDWARE_H__
#include "stm32f0.h"
#define CONCAT(a,b) a ## b
#define STR_HELPER(s) #s
#define STR(s) STR_HELPER(s)
#define FORMUSART(X) CONCAT(USART, X)
#define USARTX FORMUSART(USARTNUM)
// LEDS: 0 - PC13, 1 - PC14
// LED0
#define LED0_port GPIOC
#define LED0_pin (1<<13)
// LED1
#define LED1_port GPIOC
#define LED1_pin (1<<14)
#define LED_blink(x) pin_toggle(x ## _port, x ## _pin)
// CAN address - PB14(0), PB15(1), PA8(2)
#define READ_CAN_INV_ADDR() (((GPIOA->IDR & (1<<8))>>6)|((GPIOB->IDR & (3<<14))>>14))
void gpio_setup(void);
#endif // __HARDWARE_H__

View File

@ -0,0 +1,12 @@
/* Linker script for STM32F042x6, 32K flash, 6K RAM. */
/* Define memory regions. */
MEMORY
{
rom (rx) : ORIGIN = 0x08000000, LENGTH = 32K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 6K
}
/* Include the common ld script. */
INCLUDE stm32f0.ld

123
F0-nolib/canbus/src/main.c Normal file
View File

@ -0,0 +1,123 @@
/*
* main.c
*
* Copyright 2017 Edward V. Emelianoff <eddy@sao.ru, edward.emelianoff@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "hardware.h"
#include "usart.h"
#include "can.h"
volatile uint32_t Tms = 0;
/* Called when systick fires */
void sys_tick_handler(void){
++Tms;
}
void iwdg_setup(){
/* Enable the peripheral clock RTC */
/* (1) Enable the LSI (40kHz) */
/* (2) Wait while it is not ready */
RCC->CSR |= RCC_CSR_LSION; /* (1) */
while((RCC->CSR & RCC_CSR_LSIRDY) != RCC_CSR_LSIRDY); /* (2) */
/* Configure IWDG */
/* (1) Activate IWDG (not needed if done in option bytes) */
/* (2) Enable write access to IWDG registers */
/* (3) Set prescaler by 64 (1.6ms for each tick) */
/* (4) Set reload value to have a rollover each 2s */
/* (5) Check if flags are reset */
/* (6) Refresh counter */
IWDG->KR = IWDG_START; /* (1) */
IWDG->KR = IWDG_WRITE_ACCESS; /* (2) */
IWDG->PR = IWDG_PR_PR_1; /* (3) */
IWDG->RLR = 1250; /* (4) */
while(IWDG->SR); /* (5) */
IWDG->KR = IWDG_REFRESH; /* (6) */
}
int main(void){
uint32_t lastT = 0;
int L;
char *txt;
sysreset();
SysTick_Config(6000, 1);
gpio_setup();
usart_setup();
iwdg_setup();
readCANaddr();
CAN_setup();
SEND("Greetings! My address is ");
printu(getCANaddr());
newline();
if(RCC->CSR & RCC_CSR_IWDGRSTF){ // watchdog reset occured
SEND("WDGRESET=1\n");
}
if(RCC->CSR & RCC_CSR_SFTRSTF){ // software reset occured
SEND("SOFTRESET=1\n");
}
RCC->CSR |= RCC_CSR_RMVF; // remove reset flags
while (1){
IWDG->KR = IWDG_REFRESH; // refresh watchdog
if(lastT > Tms || Tms - lastT > 499){
LED_blink(LED0);
lastT = Tms;
}
can_proc();
if(usartrx()){ // usart1 received data, store in in buffer
L = usart_getline(&txt);
char _1st = txt[0];
if(L == 2 && txt[1] == '\n'){
L = 0;
switch(_1st){
case 'C':
can_send_dummy();
break;
case 'G':
SEND("Can address: ");
printu(getCANaddr());
newline();
break;
case 'R':
NVIC_SystemReset();
break;
case 'W':
SEND("Wait for reboot\n");
while(1){nop();};
break;
default: // help
SEND(
"'C' - send dummy byte over CAN\n"
"'G' - get CAN address\n"
"'R' - software reset\n"
"'W' - test watchdog\n"
);
break;
}
}
}
if(L){ // text waits for sending
while(LINE_BUSY == usart_send(txt, L));
L = 0;
}
}
return 0;
}

238
F0-nolib/canbus/src/usart.c Normal file
View File

@ -0,0 +1,238 @@
/*us
* usart.c
*
* Copyright 2017 Edward V. Emelianoff <eddy@sao.ru, edward.emelianoff@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "stm32f0.h"
#include "hardware.h"
#include "usart.h"
#include <string.h>
extern volatile uint32_t Tms;
static int datalen[2] = {0,0}; // received data line length (including '\n')
volatile int linerdy = 0, // received data ready
dlen = 0, // length of data (including '\n') in current buffer
bufovr = 0, // input buffer overfull
txrdy = 1 // transmission done
;
int rbufno = 0; // current rbuf number
static char rbuf[UARTBUFSZ][2], tbuf[UARTBUFSZ]; // receive & transmit buffers
static char *recvdata = NULL;
/**
* return length of received data (without trailing zero
*/
int usart_getline(char **line){
if(bufovr){
bufovr = 0;
linerdy = 0;
return 0;
}
*line = recvdata;
linerdy = 0;
return dlen;
}
TXstatus usart_send(const char *str, int len){
if(!txrdy) return LINE_BUSY;
if(len > UARTBUFSZ) return STR_TOO_LONG;
txrdy = 0;
memcpy(tbuf, str, len);
#if USARTNUM == 2
DMA1_Channel4->CCR &= ~DMA_CCR_EN;
DMA1_Channel4->CNDTR = len;
DMA1_Channel4->CCR |= DMA_CCR_EN; // start transmission
#elif USARTNUM == 1
DMA1_Channel2->CCR &= ~DMA_CCR_EN;
DMA1_Channel2->CNDTR = len;
DMA1_Channel2->CCR |= DMA_CCR_EN;
#else
#error "Not implemented"
#endif
return ALL_OK;
}
TXstatus usart_send_blocking(const char *str, int len){
if(!txrdy) return LINE_BUSY;
int i;
bufovr = 0;
for(i = 0; i < len; ++i){
USARTX -> TDR = *str++;
while(!(USARTX->ISR & USART_ISR_TXE));
}
return ALL_OK;
}
void usart_putchar(const char ch){
while(!txrdy);
USARTX -> TDR = ch;
while(!(USARTX->ISR & USART_ISR_TXE));
}
void newline(){
while(!txrdy);
USARTX -> TDR = '\n';
while(!(USARTX->ISR & USART_ISR_TXE));
}
void usart_setup(){
// Nucleo's USART2 connected to VCP proxy of st-link
#if USARTNUM == 2
// setup pins: PA2 (Tx - AF1), PA15 (Rx - AF1)
// AF mode (AF1)
GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER2|GPIO_MODER_MODER15))\
| (GPIO_MODER_MODER2_AF | GPIO_MODER_MODER15_AF);
GPIOA->AFR[0] = (GPIOA->AFR[0] &~GPIO_AFRH_AFRH2) | 1 << (2 * 4); // PA2
GPIOA->AFR[1] = (GPIOA->AFR[1] &~GPIO_AFRH_AFRH7) | 1 << (7 * 4); // PA15
// DMA: Tx - Ch4
DMA1_Channel4->CPAR = (uint32_t) &USART2->TDR; // periph
DMA1_Channel4->CMAR = (uint32_t) tbuf; // mem
DMA1_Channel4->CCR |= DMA_CCR_MINC | DMA_CCR_DIR | DMA_CCR_TCIE; // 8bit, mem++, mem->per, transcompl irq
// Tx CNDTR set @ each transmission due to data size
NVIC_SetPriority(DMA1_Channel4_5_IRQn, 3);
NVIC_EnableIRQ(DMA1_Channel4_5_IRQn);
NVIC_SetPriority(USART2_IRQn, 0);
// setup usart2
RCC->APB1ENR |= RCC_APB1ENR_USART2EN; // clock
// oversampling by16, 115200bps (fck=48mHz)
//USART2_BRR = 0x1a1; // 48000000 / 115200
USART2->BRR = 480000 / 1152;
USART2->CR3 = USART_CR3_DMAT; // enable DMA Tx
USART2->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE; // 1start,8data,nstop; enable Rx,Tx,USART
while(!(USART2->ISR & USART_ISR_TC)); // polling idle frame Transmission
USART2->ICR |= USART_ICR_TCCF; // clear TC flag
USART2->CR1 |= USART_CR1_RXNEIE;
NVIC_EnableIRQ(USART2_IRQn);
// USART1 of main board
#elif USARTNUM == 1
// PA9 - Tx, PA10 - Rx (AF1)
GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER9 | GPIO_MODER_MODER10))\
| (GPIO_MODER_MODER9_AF | GPIO_MODER_MODER10_AF);
GPIOA->AFR[1] = (GPIOA->AFR[1] & ~(GPIO_AFRH_AFRH1 | GPIO_AFRH_AFRH2)) |
1 << (1 * 4) | 1 << (2 * 4); // PA9, PA10
// USART1 Tx DMA - Channel2 (default value in SYSCFG_CFGR1)
DMA1_Channel2->CPAR = (uint32_t) &USART1->TDR; // periph
DMA1_Channel2->CMAR = (uint32_t) tbuf; // mem
DMA1_Channel2->CCR |= DMA_CCR_MINC | DMA_CCR_DIR | DMA_CCR_TCIE; // 8bit, mem++, mem->per, transcompl irq
// Tx CNDTR set @ each transmission due to data size
NVIC_SetPriority(DMA1_Channel2_3_IRQn, 3);
NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
NVIC_SetPriority(USART1_IRQn, 0);
// setup usart1
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
USART1->BRR = 480000 / 1152;
USART1->CR3 = USART_CR3_DMAT; // enable DMA Tx
USART1->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE; // 1start,8data,nstop; enable Rx,Tx,USART
while(!(USART1->ISR & USART_ISR_TC)); // polling idle frame Transmission
USART1->ICR |= USART_ICR_TCCF; // clear TC flag
USART1->CR1 |= USART_CR1_RXNEIE;
NVIC_EnableIRQ(USART1_IRQn);
#else
#error "Not implemented"
#endif
}
#if USARTNUM == 2
void usart2_isr(){
// USART1
#elif USARTNUM == 1
void usart1_isr(){
#else
#error "Not implemented"
#endif
#ifdef CHECK_TMOUT
static uint32_t tmout = 0;
#endif
if(USARTX->ISR & USART_ISR_RXNE){ // RX not emty - receive next char
#ifdef CHECK_TMOUT
if(tmout && Tms >= tmout){ // set overflow flag
bufovr = 1;
datalen[rbufno] = 0;
}
tmout = Tms + TIMEOUT_MS;
if(!tmout) tmout = 1; // prevent 0
#endif
// read RDR clears flag
uint8_t rb = USARTX->RDR;
if(datalen[rbufno] < UARTBUFSZ){ // put next char into buf
rbuf[rbufno][datalen[rbufno]++] = rb;
if(rb == '\n'){ // got newline - line ready
linerdy = 1;
dlen = datalen[rbufno];
recvdata = rbuf[rbufno];
// prepare other buffer
rbufno = !rbufno;
datalen[rbufno] = 0;
#ifdef CHECK_TMOUT
// clear timeout at line end
tmout = 0;
#endif
}
}else{ // buffer overrun
bufovr = 1;
datalen[rbufno] = 0;
#ifdef CHECK_TMOUT
tmout = 0;
#endif
}
}
}
// print 32bit unsigned int
void printu(uint32_t val){
char bufa[11], bufb[10];
int l = 0, bpos = 0;
if(!val){
bufa[0] = '0';
l = 1;
}else{
while(val){
bufb[l++] = val % 10 + '0';
val /= 10;
}
int i;
bpos += l;
for(i = 0; i < l; ++i){
bufa[--bpos] = bufb[i];
}
}
while(LINE_BUSY == usart_send_blocking(bufa, l+bpos));
}
#if USARTNUM == 2
void dma1_channel4_5_isr(){
if(DMA1->ISR & DMA_ISR_TCIF4){ // Tx
DMA1->IFCR |= DMA_IFCR_CTCIF4; // clear TC flag
txrdy = 1;
}
}
// USART1
#elif USARTNUM == 1
void dma1_channel2_3_isr(){
if(DMA1->ISR & DMA_ISR_TCIF2){ // Tx
DMA1->IFCR |= DMA_IFCR_CTCIF2; // clear TC flag
txrdy = 1;
}
}
#else
#error "Not implemented"
#endif

View File

@ -0,0 +1,60 @@
/*
* usart.h
*
* Copyright 2017 Edward V. Emelianoff <eddy@sao.ru, edward.emelianoff@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#pragma once
#ifndef __USART_H__
#define __USART_H__
// input and output buffers size
#define UARTBUFSZ (64)
// timeout between data bytes
#ifndef TIMEOUT_MS
#define TIMEOUT_MS (1500)
#endif
// macro for static strings
#define SEND(str) do{}while(LINE_BUSY == usart_send_blocking(str, sizeof(str)-1))
#ifdef EBUG
#define MSG(str) do{SEND(__FILE__ " (L" STR(__LINE__) "): " str);}while(0)
#else
#define MSG(str)
#endif
typedef enum{
ALL_OK,
LINE_BUSY,
STR_TOO_LONG
} TXstatus;
#define usartrx() (linerdy)
#define usartovr() (bufovr)
extern volatile int linerdy, bufovr, txrdy;
void usart_setup();
int usart_getline(char **line);
TXstatus usart_send(const char *str, int len);
TXstatus usart_send_blocking(const char *str, int len);
void newline();
void usart_putchar(const char ch);
void printu(uint32_t val);
#endif // __USART_H__

View File

@ -200,8 +200,8 @@ TRUE_INLINE void StartHSI48(){
/************************* ADC *************************/ /************************* ADC *************************/
/* inner termometer calibration values /* inner termometer calibration values
* Temp = (Vsense - V30)/Avg_Slope + 30 * Temp = (V30 - Vsense)/Avg_Slope + 30
* Avg_Slope = (V110 - V30) / (110 - 30) * Avg_Slope = (V30 - V110) / (110 - 30)
*/ */
#define TEMP110_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FFFF7C2)) #define TEMP110_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FFFF7C2))
#define TEMP30_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FFFF7B8)) #define TEMP30_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FFFF7B8))
@ -216,6 +216,12 @@ TRUE_INLINE void StartHSI48(){
// set address/character match value // set address/character match value
#define USART_CR2_ADD_VAL(x) ((x) << USART_CR2_ADD_SHIFT) #define USART_CR2_ADD_VAL(x) ((x) << USART_CR2_ADD_SHIFT)
/************************* IWDG *************************/
#define IWDG_REFRESH (uint32_t)(0x0000AAAA)
#define IWDG_WRITE_ACCESS (uint32_t)(0x00005555)
#define IWDG_START (uint32_t)(0x0000CCCC)
//#define do{}while(0) //#define do{}while(0)

3
README
View File

@ -8,3 +8,6 @@ F1 - for STM32F103
WARNING!!! WARNING!!!
arm-none-eabi-gcc from gentoo have a bug with division on F0. arm-none-eabi-gcc from gentoo have a bug with division on F0.
Use toolchain from https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads instead! Use toolchain from https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads instead!
CMSIS-headers:
https://github.com/modm-io/cmsis-header-stm32