Cov txheej txheem:

Bare Metal Raspberry Pi 3: Teeb LED: 8 Kauj Ruam
Bare Metal Raspberry Pi 3: Teeb LED: 8 Kauj Ruam

Video: Bare Metal Raspberry Pi 3: Teeb LED: 8 Kauj Ruam

Video: Bare Metal Raspberry Pi 3: Teeb LED: 8 Kauj Ruam
Video: Dave Mustaine sneaks into seats behind fans secretly handing kids guitar picks 2024, Kaum ib hlis
Anonim
Bare Metal Raspberry Pi 3: Teeb LED
Bare Metal Raspberry Pi 3: Teeb LED

Ua raws ntau los ntawm tus sau:

Raspberry Pi Push Button With LEDs Bare Metal
Raspberry Pi Push Button With LEDs Bare Metal
Raspberry Pi Push Button With LEDs Bare Metal
Raspberry Pi Push Button With LEDs Bare Metal
Crates
Crates
Crates
Crates
Yuav Ua Li Cas Thiaj Li Carving rau Veterans Day
Yuav Ua Li Cas Thiaj Li Carving rau Veterans Day
Yuav Ua Li Cas Thiaj Li Carving rau Veterans Day
Yuav Ua Li Cas Thiaj Li Carving rau Veterans Day

Txog:.oO0Oo. Xav paub ntau ntxiv txog moldypizza »

Txais tos rau BARE METAL pi 3 Blinking LED tutorial!

Hauv qhov kev qhia no peb yuav dhau los ntawm cov theem, txij thaum pib mus txog qhov kawg, kom tau txais LED ntsais muag siv lub Raspberry PI 3, lub khob cij, tus tiv thaiv, tus coj, thiab daim npav SD dawb paug.

Yog li BARE METAL yog dab tsi? BARE METAL tsis yog qhov kev ua kom zoo nkauj. Cov hlau liab txhais tau tias peb tau ua tiav ntawm kev tswj hwm lub computer yuav ua dab tsi. Yog li nws ib txwm txhais tau tias cov cai yuav raug sau tag nrho hauv kev sib dhos, siv Arm qhia kev teeb tsa. Thaum kawg peb yuav tau tsim ib qhov program uas yuav ntsais muag LED los ntawm kev nkag mus rau lub chaw nyob ntawm ib qho ntawm Raspberry Pi's GPIO pins thiab teeb tsa nws kom tso tawm thiab tom qab ntawd hloov nws rau thiab tawm. Sim ua txoj haujlwm no, yog txoj hauv kev zoo los pib nrog kev tsim cov phiaj xwm thiab vam tias yuav muab kev nkag siab zoo ntawm lub computer ua haujlwm li cas.

Koj xav tau dab tsi?

Kho vajtse

  • Raspberry PI 3
  • SD daim npav ua ntej thauj khoom nrog daim duab bootable
  • Cov qhob cij
  • Txiv neej Poj niam jumper xov hlau
  • Txiv neej Txiv neej jumper xov hlau
  • LED
  • 220 ohm resistor (tsis tas yuav tsum yog 220 ohms, feem ntau cov resistor yuav ua haujlwm)
  • mini sd card
  • mini sd card ua ntej thauj khoom nrog raspberry pi operating system (feem ntau suav nrog pi)

Software

  • GCC tus tsim tawm
  • GNU embedded toolchain
  • ntawv editor
  • sd daim ntawv formatter

Zoo, Cia Peb Pib!

Kauj Ruam 1: TSEEB TSHAJ PLAWS/STUFF UP

TSEEM YUAV TSHUAB/STUFF UP
TSEEM YUAV TSHUAB/STUFF UP

Yog li ntawd … thawj kauj ruam yog kom tau txais khoom kho vajtse. Koj tuaj yeem yuav cov khoom sib cais lossis muaj cov khoom siv uas los nrog ntau dua qhov txaus. LINK

Cov khoom siv no los nrog txhua yam xav tau los teeb tsa raspberry pi 3 thiab ntau dua! qhov tsuas yog tsis suav nrog hauv cov khoom siv no yog daim npav mini sd ntxiv. Tos! Tsis txhob yuav lwm tus tam sim no. Yog tias koj tsis npaj rau kev siv linux teeb tsa ua ntej ntawm daim npav ces tsuas yog luam cov ntsiab lus ntawm suav nrog daim npav mini rau yav tom ntej thiab rov ua daim npav (ntau ntxiv tom qab ntawd). CEEB TOOM CEEB TOOM: nco ntsoov tias koj khaws cov ntaub ntawv ntawm daim npav uas koj yuav xav tau tom qab!

Tom ntej no yog lub sijhawm los teeb tsa software. Phau ntawv qhia no yuav tsis suav nrog cov lus qhia ntxaws txog yuav ua li cas rau nruab software. Muaj ntau qhov peev txheej thiab qhia hauv online ntawm yuav ua li cas rau nruab cov no:

Cov neeg siv WINDOWS:

Rub tawm thiab teeb tsa gcc

Tom ntej no, rub tawm thiab teeb tsa GNU ARM embedded toolchain

LINUX/MAC

  • Linux kev faib khoom tuaj nrog gcc ua ntej teeb tsa
  • Rub tawm thiab teeb tsa GNU ARM embedded toolchain.

Yog li yog tias txhua yam mus tau zoo ces koj yuav tsum tuaj yeem qhib lub davhlau ya nyob twg (linux/mac) lossis kab cmd (windows) thiab sim ntaus ntawv

caj npab-tsis-eabi-gcc

Cov zis yuav tsum zoo ib yam li thawj daim duab. Qhov no tsuas yog txhawm rau txheeb xyuas tias nws tau teeb tsa raug.

Zoo tam sim no tias qhov kev xav tau ua ntej yog txoj hauv kev, nws yog lub sijhawm kom pib nrog cov khoom lom zem.

Kauj Ruam 2: CIRCUIT

CIRCUIT
CIRCUIT
CIRCUIT
CIRCUIT
CIRCUIT
CIRCUIT

Lub sijhawm luv luv! Lub voj voog rau qhov no yog qhov yooj yim. Peb yuav txuas tus coj mus rau GPIO 21 (tus pin 40) ntawm pi (saib daim duab 2 thiab 3). Ib tus tiv thaiv kuj tseem txuas nrog ua ntu zus los tiv thaiv cov coj los ntawm kev puas tsuaj. Tus tiv thaiv yuav txuas nrog rau kab lus tsis zoo ntawm lub khob cij uas yuav txuas nrog GND (tus lej 39) ntawm tus pi. Thaum txuas tus coj kom ntseeg tau tias txuas txuas qhov kawg mus rau qhov tsis zoo. Saib daim duab kawg

Kauj ruam 3: BOOTABLE Mini SD

BOOTABLE Mini SD
BOOTABLE Mini SD
BOOTABLE Mini SD
BOOTABLE Mini SD
BOOTABLE Mini SD
BOOTABLE Mini SD

Muaj peb kauj ruam kom tau txais koj tus pi 3 kom paub txog koj daim npav mini sd dawb paug. Peb yuav tsum nrhiav thiab luam bootcode.bin, pib.elf, thiab fixup.dat. Koj tuaj yeem tau txais cov ntaub ntawv no suav nrog daim npav mini sd yog tias koj yuav lub canakit lossis ua daim npav SD bootable rau pi 3 nrog kev faib linux. Ob txoj hauv kev no cov ntaub ntawv tsim nyog los tso cai rau pi kom paub txog daim npav SD ua lub cuab yeej bootable. Tom ntej no, teeb tsa lub mini sd rau fat32 (feem ntau daim npav mini sd tuaj yeem ua rau hauv fat32. Kuv siv daim npav mini pheej yig los ntawm sandisk), txav bootcode.bin, pib.elf, fixup.dat mus rau daim npav SD. Thiab koj ua tiav! Okay ib zaug ntxiv thiab nyob rau hauv qhov kev txiav txim ntawm cov duab cov kauj ruam yog:

  1. Nrhiav bootcode.bin, start.elf, fixup.dat.
  2. Nco ntsoov tias koj daim npav SD tau teeb tsa rau fat32.
  3. Txav mus rau bootcode.bin, pib.elf, thiab fixup.dat mus rau daim ntawv SD daim ntawv.

Nov yog qhov kuv xam pom qhov no, txuas.

Kauj ruam 4: Txheeb xyuas Mini SD

Txheeb xyuas Mini SD
Txheeb xyuas Mini SD
Txheeb xyuas Mini SD
Txheeb xyuas Mini SD

Yog lawm, peb muaj daim npav mini bootable, thiab cia siab tias, koj muaj pi 3 ntawm qhov no. Yog li tam sim no peb yuav tsum ntsuas nws kom paub tseeb tias pi 3 tau lees paub lub mini sd card li bootable.

Ntawm tus pi, ze ntawm qhov chaw nres nkoj mini usb muaj ob lub coj me me. Ib qho yog liab. Qhov no yog qhov taw qhia lub zog. Thaum tus pi tau txais lub hwj chim lub teeb no yuav tsum qhib. Yog li yog tias koj ntsaws koj tus pi tam sim no uas tsis muaj daim npav mini sd nws yuav tsum teeb liab. Okay tam sim no ntsaws koj tus pi thiab muab tso rau hauv koj lub bootable mini sd card uas tau tsim hauv cov kauj ruam dhau los thiab ntsaws tus pi rau hauv. Koj puas pom lwm lub teeb? Yuav tsum muaj lub teeb ntsuab, nyob ib sab ntawm tus liab, uas qhia tias nws tab tom nyeem daim npav SD. Cov coj no hu ua ACT coj. Nws yuav ci ntsa iab thaum muaj daim npav sd siv tau. Nws yuav nyem thaum nws nkag mus rau koj daim npav mini sd.

Okay yog li ob yam yuav tsum tau tshwm sim tom qab koj tso lub bootable mini sd card thiab ntsaws tus pi hauv:

  1. Cov coj liab yuav tsum tau teeb pom kev qhia lub zog txais tos
  2. Cov coj ntsuab yuav tsum tau teeb pom kev qhia tias nws tau khau raj rau hauv daim npav mini sd

Yog tias muaj qee yam tsis raug sim rov ua cov kauj ruam dhau los lossis nyem rau kab ntawv txuas hauv qab no kom paub ntau ntxiv.

Txuas ntawm no yog qhov siv tau zoo.

Kauj ruam 5: CODE1

Txoj haujlwm no tau sau ua lus ARM los ua ke. Kev nkag siab yooj yim ntawm kev sib dhos ARM yog xav hauv qhov kev qhia no, tab sis ntawm no yog qee yam uas koj yuav tsum paub:

.equ: muab tus nqi rau lub cim piv txwv li abc.equ 5 abc tam sim no sawv cev rau tsib

  • ldr: thauj khoom los ntawm kev nco
  • str: sau rau nco
  • cmp: sib piv ob qhov txiaj ntsig los ntawm kev ua rho tawm. Teem chij.
  • b: ceg rau daim ntawv lo
  • ntxiv: ua cov lej

Yog tias koj tsis muaj kev paub nrog Arm sib dhos saib cov vis dis aus no. Nws yuav muab rau koj nkag siab zoo ntawm cov lus sib dhos ntawm caj npab.

Yog li tam sim no peb muaj lub xov tooj sib txuas uas txuas nrog peb lub raspberry pi 3 thiab peb muaj daim npav SD uas tus pi lees paub, yog li peb txoj haujlwm tom ntej yog xam tawm yuav ua li cas cuam tshuam nrog Circuit Court los ntawm kev thau cov pi nrog txoj haujlwm ua haujlwm. Feem ntau, yam peb yuav tsum tau ua yog qhia tus pi kom tso tawm qhov hluav taws xob los ntawm GPIO 21 (tus pin txuas nrog xaim liab). Tom qab ntawd peb xav tau txoj hauv kev toggle tus coj kom nws ntsais muag. Txhawm rau ua qhov no peb xav tau cov ntaub ntawv ntxiv. Txog tam sim no peb tsis muaj lub tswv yim yuav qhia GPIO 21 mus rau qhov twg uas yog vim li cas peb yuav tsum nyeem cov ntawv teev npe. Feem ntau cov tswj hwm micro muaj cov ntaub ntawv-nplooj ntawv uas qhia meej meej tias txhua yam ua haujlwm li cas. Hmoov tsis zoo, pi 3 tsis muaj ntaub ntawv raug cai! Txawm li cas los xij, muaj cov ntaub ntawv tsis raug cai-daim ntawv. Nov yog ob qhov txuas rau nws:

  1. github.com/raspberrypi/documentation/files…
  2. web.stanford.edu/class/cs140e/docs/BCM2837…

Okay ntawm qhov no, koj yuav tsum siv sijhawm li ob peb feeb ua ntej txav mus rau cov kauj ruam tom ntej los saib los ntawm cov ntaub ntawv-ntawv thiab saib cov ntaub ntawv twg koj tuaj yeem nrhiav tau.

Kauj Ruam 6: CODE2: Turn_Led_ON

CODE2: Turn_Led_ON
CODE2: Turn_Led_ON
CODE2: Turn_Led_ON
CODE2: Turn_Led_ON
CODE2: Turn_Led_ON
CODE2: Turn_Led_ON

Raspberry pi 3 53 sau npe los tswj cov zis/tawm tswv yim (cov khoom siv sab nraud). Cov koob tau koom ua ke thiab txhua pab pawg tau muab rau npe. Txog GPIO peb yuav tsum muaj peev xwm nkag mus rau SELECT sau npe, SET sau npe, thiab CLEAR sau npe. Txhawm rau nkag mus rau cov npe no peb xav tau lub chaw nyob ntawm cov npe no. Thaum koj tab tom nyeem cov ntaub ntawv-koj tsuas yog xav kom sau tseg qhov chaw nyob (lo byte) thiab ntxiv qhov ntawd mus rau qhov chaw nyob. Koj yuav tsum ua qhov no vim hais tias cov ntawv teev npe ntawm linux virtual chaw nyob uas yog qhov tseem ceeb uas cov haujlwm ua haujlwm muab. Peb tsis siv lub kaw lus ua haujlwm yog li peb yuav tsum nkag mus rau cov npe no ncaj qha los ntawm kev siv lub chaw nyob. Rau qhov no koj xav tau cov ntaub ntawv hauv qab no:

  • Qhov Chaw Nyob Ntawm Cov Khoom Siv Hluav Taws Xob: 0x3f200000. Pdf (nplooj 6) hais tias qhov chaw nyob yog 0x3f000000, txawm li cas los xij, qhov chaw nyob no yuav tsis ua haujlwm. Siv 0x3f200000
  • Offset ntawm FSEL2 (SELECT) tsis yog qhov chaw nyob ntawm qhov sau npe. Pdf sau FSEL2 ntawm 0x7E20008 tab sis qhov chaw nyob no hais txog linux virtual chaw nyob. Cov offset yuav zoo ib yam yog li qhov peb xav kom nco ntsoov. 0 x8x
  • Offset ntawm GPSET0 (SET): 0x1c
  • Offset ntawm GPCLR0 (CLEAR): 0x28

Yog li koj yuav pom tias cov ntaub ntawv-teev 4 SELECT sau npe, 2 SET sau npe, thiab 2 CLEAR sau npe yog vim li cas kuv thiaj xaiv qhov kuv tau ua? Qhov no yog vim peb xav siv GPIO 21 thiab FSEL2 tswj GPIO 20-29, SET0 thiab CLR0 tswj GPIO 0-31. FSEL cov ntawv sau npe muab peb qho rau txhua tus lej GPIO. Txij li thaum peb siv FSEL2 uas txhais tau tias cov khoom 0-2 tswj GPIO 20, thiab cov khoom 3-5 tswj GPIO 21 thiab ntxiv rau. Teeb thiab CLR cov ntawv sau npe muab me ntsis rau txhua tus pin. Piv txwv, me ntsis 0 hauv SET0 thiab CLR0 tswj GPIO 1. Txhawm rau tswj GPIO 21 koj yuav teeb tsa me ntsis 21 hauv SET0 thiab CLR0.

Okay yog li peb tau tham txog yuav ua li cas nkag mus rau cov npe no, tab sis txhua yam nws txhais li cas?

  • FSEL2 sau npe yuav raug siv los teeb tsa GPIO 21 rau qhov tso tawm. Txhawm rau teeb tus pin rau qhov tso tawm koj yuav tsum teeb tsa lo me ntsis ntawm peb qhov khoom rau 1. Yog li yog cov khoom 3-5 tswj GPIO 21 uas txhais tau tias peb yuav tsum teeb tsa thawj zaug, ntsis 3 txog 1. Qhov no yuav qhia rau pi tias peb xav siv GPIO 21 ua qhov tso tawm. Yog li yog tias peb tau saib 3 qhov khoom rau GPIO 21 lawv yuav tsum zoo li qhov no tom qab peb teeb tsa nws kom tso tawm, b001.
  • GPSET0 qhia tus pi qhib tus pin (tso tawm qhov hluav taws xob). Txhawm rau ua qhov no peb tsuas yog hloov me ntsis uas sib haum nrog tus pin GPIO peb xav tau. Hauv peb, rooj me ntsis 21.
  • GPCLR0 qhia tus pi kom tua tus pin (tsis muaj qhov hluav taws xob). Txhawm rau tua tus pin teeb tsa me ntsis rau tus pin GPIO sib xws. Hauv peb kis me ntsis 21

Ua ntej peb mus rau qhov muag ntsais muag, ua ntej cia ua qhov program yooj yim uas yuav yooj yim tig rau ntawm tus coj.

Txhawm rau pib tawm peb yuav tsum ntxiv ob txoj kev coj mus rau sab saum toj ntawm peb qhov chaws.

  • .section.init qhia tus pi qhov twg tso cov cai
  • .global _ pib

Tom ntej no, peb yuav tsum teeb tsa txhua qhov chaw nyob uas peb yuav siv. Siv.equ los muab cov cim uas nyeem tau rau tus nqi.

  • .equ GPFSEL2, 0x08
  • .equ GPSET0, 0x1c
  • .equ GPCLR0, 0x28
  • .equ BASE, 0x3f200000

Tam sim no peb tab tom tsim lub qhov ncauj qhov ntswg los teeb cov khoom uas peb xav tau los teeb tsa.

  • .equ SET_BIT3, 0x08 Qhov no yuav teeb tsa me ntsis peb 0000_1000
  • .equ SET_BIT21, 0x200000

Tom qab ntawd peb yuav tsum ntxiv peb daim ntawv _start

_ pib:

Thauj chaw nyob hauv paus rau npe

ldr r0, = LOJ

Tam sim no peb yuav tsum teeb tsa bit3 ntawm GPFSEL2

  • ldr r1, SET_BIT3
  • str r1, [r0, #GPFSEL2] Cov lus qhia no hais kom sau rov qab me ntsis 0x08 mus rau qhov chaw nyob ntawm GPFSEL2

Thaum kawg peb yuav tsum teeb tsa GPIO 21 rau los ntawm teeb tsa me ntsis 21 hauv GPSET0 sau npe

  • ldr r1, = SET_BIT21
  • str r1, [r0, #GPSET0]

Cov khoom kawg yuav tsum saib qee yam zoo li cov cai hauv daim duab.

Cov kauj ruam tom ntej yog sau cov cai thiab tsim cov ntaub ntawv.img uas pi tuaj yeem ua haujlwm.

  • Rub tawm daim ntawv txuas ua ke, thiab kernel.ld thiab yog tias koj xav tau turn_led_on.s qhov chaws.
  • Muab tag nrho cov ntaub ntawv tso rau hauv tib daim nplaub tshev.
  • Yog tias koj siv koj tus kheej qhov chaws hloov kho cov makefile thiab hloov cov cai = turn_led_on.s nrog code =.s
  • Txuag lub makefile.
  • Siv lub davhlau ya nyob twg (linux) lossis cmd window (windows) mus rau koj lub nplaub tshev uas muaj cov ntaub ntawv thiab ntaus ua thiab ntaus nkag
  • Cov ntawv ua yuav tsum tsim cov ntaub ntawv hu ua kernel.img
  • Luam kernel.img rau koj daim npav mini SD. Koj daim npav cov ntsiab lus yuav tsum zoo li daim duab (duab 3): bootcode.bin, start.elf, fixup.dat, thiab kernel.img.
  • Tshem daim npav mini sd thiab ntxig rau hauv pi
  • Plug pi rau hauv lub zog siv
  • LED yuav tsum teeb !!!

CEEB TOOM QHOV TSEEB QHOV TSEEM CEEB: Yooj yim qhia tau tias muaj teeb meem nrog cov makefile tsis muaj qhov txuas ntxiv, yog li kuv rov tso nws dua nrog.txt ncua ntxiv. Thov tshem qhov txuas ntxiv thaum koj rub tawm nws kom nws ua haujlwm tau zoo.

Pom zoo: