Cov txheej txheem:

Ntu 1 ARM Sibtham TI RSLK Robotics Learning Curriculum Lab 7 STM32 Nucleo: 16 Kauj Ruam
Ntu 1 ARM Sibtham TI RSLK Robotics Learning Curriculum Lab 7 STM32 Nucleo: 16 Kauj Ruam

Video: Ntu 1 ARM Sibtham TI RSLK Robotics Learning Curriculum Lab 7 STM32 Nucleo: 16 Kauj Ruam

Video: Ntu 1 ARM Sibtham TI RSLK Robotics Learning Curriculum Lab 7 STM32 Nucleo: 16 Kauj Ruam
Video: Elon Musk Laughs at the Idea of Getting a PhD... and Explains How to Actually Be Useful! 2024, Hlis ntuj nqeg
Anonim
Image
Image

Lub hom phiaj ntawm Phau Ntawv Qhia no yog STM32 Nucleo micro-controller. Kev txhawb siab rau qhov no kom muaj peev xwm los tsim cov phiaj xwm sib dhos los ntawm cov pob txha liab qab. Qhov no yuav pab peb nkag siab tob thiab nkag siab txog MSP432 Launchpad project (TI-RSLK) uas yog lub ncauj lus ntawm ntau Cov Lus Qhia yav dhau los.

Tsis muaj kev pab online ntau los tsim qhov phiaj xwm sib dhos nkaus xwb rau MSP432, siv Code Code Composer Studio. Txog tam sim no peb tau nyuam qhuav theej tawm/muab tshuaj txhuam los ntawm cov phiaj xwm sib dhos ua ntej. Txoj hauv kev no tau pab peb zoo.

Txawm li cas los xij, tam sim no, rau Lab 7, peb tau ntsib teeb meem me ntsis. Los yog tsawg kawg ib ntus hiccup. Lab 7 qhia txog lub xeev-cov tshuab kawg, thiab thawj qhov uas peb ntsib yog qhov xav tau los tsim thiab siv ntau qhov txiaj ntsig. Txij li thaum chav kawm TI feem ntau siv C programming - qhov no tsis yog teeb meem. Tab sis Cov Lus Qhia no tau tsom mus rau kev sib dhos, tsis yog C.

Ntxiv mus, txij li cov kab ntawv yog nyeem tau-qhov tseem ceeb, nws yuav zoo muab tso rau hauv flash nco, tsis yog RAM.

Zoo li muaj ntau qhov kev pab online rau kev sib sau ua haujlwm siv STM32 MCU, yog li, peb pib nrog Cov Lus Qhia no, nrog lub hom phiaj ntawm kev siv yam uas tau kawm, tom qab ntawv thov rau MSP432 thiab Code Composer Studio.

Ntawm txoj kev mus rau lub hom phiaj ntawd, peb tseem yuav tau txais kev paub nrog lwm qhov, nrov micro-maub los.

Kauj Ruam 1: Kev Xeem Pib ntawm Ntaus Ntawv

Kev Xeem Pib ntawm Ntaus Ntawv
Kev Xeem Pib ntawm Ntaus Ntawv
Kev Xeem Pib ntawm Ntaus Ntawv
Kev Xeem Pib ntawm Ntaus Ntawv
Kev Xeem Pib ntawm Ntaus Ntawv
Kev Xeem Pib ntawm Ntaus Ntawv

Ib zaug ntxiv, vim li cas xaiv STM32 Nucleo tshwj xeeb?

Ua siab ncaj? Vim tias kuv tau tshawb nrhiav cov ntawv zoo ntawm cov phiaj hlau tsis sib dhos rau ARM cov tswj hwm, thiab kuv tau hla cov kab ntawv no. Thiab kuj vim tias STM32 zoo li yog MCU nrov.

Kuv tau ua qee qhov kev tshawb fawb (muaj ntau qhov hloov pauv los xaiv - saib daim duab saum toj no), tab sis thaum kawg nws tau dhau los ua dab tsi kuv tuaj yeem tau txais, txij li kuv yuav siv Amazon (hauv Asmeskas).

Nws los hauv cov pob yooj yim tab sis kev tshaj lij, nrog qee cov lus qhia pib ua haujlwm. Nws yog qhov txaus luag me ntsis kom pom tias qhov demo hlawv mus rau hauv lub maub los yuav luag raws nraim qhov peb tau ua yav dhau los Cov Lus Qhia - LED teeb thiab hloov pauv nrawm raws li nias lub pob.

Nws zoo li tias pawg tswj hwm kev txhim kho no zoo ib yam li MSP432 uas muaj 2 LEDs, thiab ib tus neeg siv khawm-khawm. MSP432 muaj 2 tus neeg siv khawm.

Raws li koj tuaj yeem pom hauv cov duab, Kuv tau txaj muag me ntsis tias lub rooj tsavxwm muaj lub mini thiab tsis yog micro USB. Yuav tsum khiav tawm mus yuav ib txoj hlua.

Lwm qhov kev sim zoo yog tias thaum koj txuas nws mus rau koj lub khoos phis tawj (Kuv tab tom siv Linux lub thawv), nws tshwm nyob rau hauv kuv tus thawj tswj ntaub ntawv, ua cov ntaub ntawv kaw lus, hu ua "NODE_F303RE". Qhib uas nthuav tawm ob daim ntawv, ib qho HTML thiab ib kab ntawv.

Qhov ntawd yog nws, tab sis tsawg kawg nws tseem hais tias kev sib txuas zoo li yooj yim heev.

Tam sim no peb tau npaj pib.

Kuv yuav sim tsis rov hais dua ib qho ntawm cov ntaub ntawv zoo los ntawm IVONOMICON Bare Metal tsab xov xwm kab lus, tab sis theej nws.

Kauj Ruam 2: Qhov Tseem Ceeb

Thawj qhov peb xav tau yog tus sau.

Thiab tom qab ntawd, peb xav tau tus debugger:

devchu@chubox: ~ $ sudo apt-get install gdb-arm-none-eabiReading pob ntawv teev npe … Ua tiav Lub tsev vam khom tsob ntoo Nyeem cov ntaub ntawv hauv xeev … Ua tiav Cov pob tshiab hauv qab no yuav raug teeb tsa: gdb-arm-none-eabi 0 hloov kho, 1 tshiab teeb tsa, 0 tshem tawm thiab 8 tsis hloov kho. Yuav tsum tau txais 2,722 kB ntawm cov ntawv khaws cia. Tom qab ua haujlwm no, 7, 738 kB ntawm qhov chaw disk ntxiv yuav raug siv. Tau: 1 https://us.archive.ubuntu.com/ubuntu xenial/ntug amd64 gdb-arm-none-eabi amd64 7.10-1ubuntu3+9 [2, 722 kB] Fetched 2, 722 kB hauv 1s (1, 988 kB/s) Xaiv pob tsis tau xaiv yav dhau los gdb-arm-none-eabi. (Nyeem cov ntaub ntawv… 262428 cov ntaub ntawv thiab cov npe tam sim no tau teeb tsa.) Npaj rau unpack…/gdb-arm-none-eabi_7.10-1ubuntu3+9_amd64.deb… Unpacking gdb-arm-none-eabi (7.10-1ubuntu3+9)… Ua ua rau txiv neej -db (2.7.5-1)… Teeb gdb-arm-none-eabi (7.10-1ubuntu3+9)…

Kauj Ruam 3: Qhov Tseem Ceeb - Windows

Cov theem saum toj no xav tias peb siv Linux. Yuav ua li cas yog tias peb siv Windows?

Koj tuaj yeem mus rau ntawm caj npab Tus tsim tawm lub vev xaib, thiab muaj ntau qhov kev xaiv rub tawm muaj. Kuv siv lub tshuab Windows 8.

Thaum lub sijhawm teeb tsa, Kuv tau xaiv los teeb tsa nws rau hauv paus "C: \" tsav tsis siv Cov Ntaub Ntawv Cov Ntaub Ntawv tsuas yog vim kuv tseem siv cygwin, thiab nws tau yooj yim los tsim qhov txuas los ntawm kuv lub hauv paus rau hauv lub hauv paus C: nplaub tshev dua li txhua qhov mess nyob rau hauv txoj kev mus rau Program Cov Ntaub Ntawv (nrog qhov chaw, thiab lwm yam).

Yog li, kuv qhov chaw cygwin thiab txoj hauv kev, thiab lwm yam, zoo li:

C: / cygwin64 / home / bin / arm-none-eabi-gcc, qhov twg caj npab-tsis-eabi-gcc yog qhov txuas rau C: / GNUToolsArmEmbedded / 7.2018.q2.update / bin / arm-none-eabi- gcc ua.

Tom qab ntawd kuv tsim "dev" nplaub tshev hauv qab lub tsev cygwin, thiab qhov ntawd yog qhov uas kuv tso cov tub ntxhais kawm ntawv. (saib ntxiv hauv qab no rau cov khoom sib dhos).

Kuv tau ua qhov zoo ib yam rau gdb (npab-tsis-eabi-gdb).

Kauj Ruam 4: Dab Tsi Yog Qhov Tseem Ceeb

Yog li dab tsi yog "gcc-arm-none-eabi"?

Gnu compiler (GCC) yuav suav cov lus programming (zoo li C) rau hauv cov cai ib txwm rau lub tshuab nws tab tom ua haujlwm. Piv txwv li, yog tias koj yuav tsum suav qee qhov C code siv GCC ntawm koj lub tshuab Windows, nws yuav tsim los ua haujlwm ntawm lub tshuab Windows. Kev tsim ua tiav yuav tsis (feem ntau) khiav ntawm ARM micro-maub los.

Yog li, txhawm rau tsim cov program kom rub tawm thiab hlawv mus rau hauv ARM micro-controller (hauv peb qhov xwm txheej tam sim no uas yuav yog STM32 Nucelo), peb yuav tsum tau muab GCC lwm yam ntxiv: lub peev xwm "hla-suav sau". Ntawd yog, lub peev xwm los tsim ua kom tiav, tsis yog rau nws ib txwm muaj (thiab tus txheej txheem), tab sis rau lub hom phiaj (ARM micro-controller). Ntawd yog qhov twg "gcc-arm-none-eabi" los ua si.

Yog li ntawd "gdb-arm-none-eabi" yog dab tsi?

Thaum peb tau rub tawm thiab hlawv (flashed) qhov tshiab-tsim ua tiav rau hauv lub micro-maub los, peb yuav zaum xav kom debug nws-nqis los ntawm kab ntawm kab ntawm kab. GDB yog gnu debugger, thiab nws, ib yam nkaus, xav tau ib txoj hauv kev los ua nws txoj haujlwm, tab sis lub hom phiaj sib txawv.

Yog li, gdb-arm-none-eabi yog rau GDB, dab tsi gcc-arm-none-eabi yog rau GCC.

Lwm qhov kev hais qhia pob txhim kho yog "libnewlib-arm-none-eabi". Tus ntawd yog leej twg?

Newlib yog lub tsev qiv ntawv C thiab tsev qiv ntawv lej uas npaj siv rau hauv cov kab ke. Nws yog kev sib sau ua ke ntawm ntau lub tsev qiv ntawv, txhua qhov nyob hauv cov ntawv tso cai software dawb uas ua rau lawv siv tau yooj yim ntawm cov khoom lag luam.

Thiab thaum kawg, pob "libstdc ++-arm-none-eabi". Qhov ntawd yog qhov pom tseeb zoo nkauj; nws yog C ++ tsev qiv ntawv rau tus ntoo khaub lig-compiler; rau kos ARM micro-controllers.

Kauj ruam 5: Linker File

Cov ntaub ntawv Linker
Cov ntaub ntawv Linker
Cov ntaub ntawv Linker
Cov ntaub ntawv Linker

Cia peb tsim cov ntawv txuas.

Ib feem tseem ceeb lossis thaiv hauv cov ntawv no yuav yog MEMORY hais kom ua.

--- los ntawm sourceware.org:

Qhov txuas txuas lub neej ntawd teeb tsa tso cai faib ntawm txhua lub cim xeeb muaj. Koj tuaj yeem hla qhov no los ntawm kev siv MEMORY hais kom ua. MEMORY cov lus txib piav qhia qhov chaw nyob thiab qhov loj ntawm cov cim nco hauv lub hom phiaj. Koj tuaj yeem siv nws los piav qhia txog thaj chaw cim xeeb twg tuaj yeem siv los ntawm tus txuas, thiab thaj chaw nco nws yuav tsum zam. Tom qab ntawd koj tuaj yeem muab ntu rau thaj tsam nco tshwj xeeb. Qhov txuas txuas yuav teeb tsa ntu chaw nyob raws thaj chaw nco, thiab yuav ceeb toom txog thaj chaw uas dhau mus tas li. Tus linker yuav tsis shuffle ntu ib puag ncig kom haum rau thaj tsam uas muaj. Qhov linker tsab ntawv yuav muaj ntau qhov siv ntawm MEMORY hais kom ua, txawm li cas los xij, txhua lub cim xeeb txwv txhais tau raug kho zoo li lawv tau teev tseg hauv ib qho MEMORY hais kom ua. Syntax rau MEMORY yog:

NTUJ

{lub npe [(attr)]: ORIGIN = keeb kwm, LENGTH = len…}

Piv txwv hauv kab lus:

/* Txheeb cais qhov kawg ntawm RAM thiab txwv ntawm pawg nco* //* (4KB SRAM ntawm kab STM32F031x6, 4096 = 0x1000)*//* (RAM pib ntawm chaw nyob 0x20000000) _estack = 0x20001000;

NTUJ

{FLASH (rx): ORIGIN = 0x08000000, LENGTH = 32K RAM (rxw): ORIGIN = 0x20000000, LENGTH = 4K}

Yog li peb yuav tsum xam tawm ntau npaum li cas FLASH (rau peb cov haujlwm thiab qhov ruaj khov, thiab lwm yam) thiab ntau npaum li cas RAM (rau kev siv los ntawm txoj haujlwm; heap thiab pawg, thiab lwm yam) rau peb pawg tshwj xeeb. Qhov no tau txais me ntsis nthuav.

Daim npav me me zoo uas los nrog Nucleo hais tias nws muaj lub cim xeeb flash yog 512 Kbytes, thiab SRAM yog 80 Kbytes. Txawm li cas los xij, txuas nws mus rau USB, nws tau teeb tsa ua ib qho system nrog ob cov ntaub ntawv, thiab ob tus thawj tswj ntaub ntawv thiab GParted qhia tias nws muaj ntau dua 540+ Kbytes ntawm qhov chaw. (RAM?) Cov.

TAB SIS, sim tshem ob daim ntawv uas siv tus tswj xyuas cov ntaub ntawv, txiav tawm thiab rov txuas lub cuab yeej, tseem qhia ob daim ntawv. (thiab tus tswj xyuas cov ntaub ntawv tau lees paub qee yam vim tias muaj lub cim "xauv" me me ntawm txhua cov ntawv.

Yog li cia peb mus nrog cov lej ntawm daim npav. Yog li tam sim no peb coj tus piv txwv saum toj no thiab hloov nws mus rau peb pawg tshwj xeeb.

Koj yuav xav siv qee yam zoo li qhov hloov pauv nco hauv online, mus los ntawm dav dav KB mus rau tus lej tshwj xeeb ntawm bytes.

Tom qab ntawd koj yuav xav siv tus lej hauv online rau hex hloov pauv.

/ * Txhais qhov kawg ntawm RAM thiab txwv ntawm pawg nco */

/* (4KB SRAM ntawm kab STM32F031x6, 4096 = 0x1000)* //* piv txwv*/

/ * kauj ruam 1: (80KB SRAM ntawm STM32F303RE, 81920 = 0x14000) * // * peb pawg thawj coj */

/* kauj ruam 2, ntxiv qhov loj me me rau hex pib qhov chaw nyob (hauv qab). */

/ * (RAM pib ntawm chaw nyob 0x20000000) */

_estack = 0x20001000; / * piv txwv */

_estack = 0x20014000; / * peb pawg thawj coj */

NCO NTSOOV {

FLASH (rx): ORIGIN = 0x08000000, LENGTH = 512K

RAM (rxw): ORIGIN = 0x20000000, LENGTH = 80K

}

Cia peb hu cov ntaub ntawv saum toj no "linker.script.ld".

Kauj Ruam 6: Daim Duab Vector

Vector Rooj
Vector Rooj

Tam sim no peb tab tom tsim cov ntawv sib dhos me me (nrog cov lus qhia) ua qee qhov yooj yim heev cuam tshuam-tuav. Peb yuav ua raws li kab lus piv txwv thiab tsim cov ntaub ntawv npe "core. S".

Ib zaug ntxiv, ntawm no yog cov piv txwv cov ntaub ntawv txheem, tab sis kuv tau hloov pauv rau peb pawg tshwj xeeb:

// Cov lus qhia no piav qhia tus yam ntxwv ntawm peb cov nti thiab

// cov lus sib dhos peb yuav siv:.syntax koom ua ke /*Saib hauv qab no tom qab thaj chaws no* //*.cpu cortex-m0* / /*tawm cov kab no ntawm qhov piv txwv* /.cpu cortex-m4 /* ntxiv rau peb pawg thawj coj saib cortex. saib cov duab saum toj no hauv cov kauj ruam no * / /*.fpu softvfp * / / *tawm cov kab no ntawm qhov piv txwv * /.fpu vfpv4 / *ntxiv hloov peb pawg thawj coj saib; nws muaj FPU */.thumb // Ntiaj teb qhov chaw nco..global vtable.global reset_handler / * * Qhov tseeb vector rooj. * Tsuas yog qhov loj ntawm RAM thiab 'rov pib dua' tus tuav haujlwm yog * suav nrog, kom yooj yim. */.type vtable, %object vtable:.word_estack.word reset_handler.size vtable,.-vtable

Hmm.. Tsis yog '.align' Directive

Txawm li cas los xij, qhov ntawd tsis tseem ceeb. Ntau ntxiv txog qhov ntawd (tej zaum) tom qab.

.syntax koom ua ke

.syntax [koom ua ke | faib]

Cov lus qhia no teeb tsa Cov Lus Qhia Txheej Txheem raws li tau piav qhia hauv ntu ARM-Qhia-teeb tsa ntu

9.4.2.1 Kev Qhia Teeb Syntax Ob qhov sib txawv me ntsis yog txhawb rau ARM thiab THUMB cov lus qhia. Lub neej ntawd, faib, siv cov qauv qub uas ARM thiab THUMB cov lus qhia muaj lawv tus kheej, cais cov lus sib dhos. Tus txheej txheem tshiab, koom ua ke, uas tuaj yeem xaiv ntawm.syntax cov lus qhia.

.fpu vfpv4

GCC tus neeg suav tuaj yeem tsim cov binaries nrog ntau txoj kev xaiv hais txog ntab ntab: mos - haum rau khiav ntawm CPU's yam tsis muaj FPU - kev suav ua tiav hauv software los ntawm compiler tsim softfp - haum rau khiav ntawm CPU nrog lossis tsis muaj FPU - yuav siv FPU yog tias muaj tam sim no. Rau peb cov ntaub ntawv tshwj xeeb (koj yuav tsum tau ua koj tus kheej kev tshawb fawb), pawg neeg tshwj xeeb no FPU ua raws li vfpv4. Tej zaum koj yuav tau ua si nrog qhov no. Los yog tseem tso nws ntawm softfp.

.thumb (vs.arm)

Cov ARM microcontroller no muaj qhov sib xyaw ntawm cov lus qhia. Ib qho yog ARM, lwm tus yog THUMB. Ib qhov sib txawv yog 16-ntsis cov lus qhia vs 32-ntsis cov lus qhia. Yog li, cov lus qhia no qhia rau tus neeg sib tham los kho cov lus qhia tom ntej xws li THUMB lossis ARM.

Peb tab tom yuav tsuas yog siv cov ntaub ntawv raws li-vim tias Cov Ntawv Qhia no tseem tsis tau raug xa mus rau qhov cuam tshuam-tsav kev sib dhos ua haujlwm.

Kauj Ruam 7: Lub Rooj Sib Tham Version ntawm 'Hello World' Program

Cov hauv qab no tseem tuaj yeem nkag mus rau yav dhau los-tsim "core. S" cov ntaub ntawv. Qhov no, dua, yog los ntawm qhov piv txwv hauv kab lus.

/ * * Tus tuav tes rov pib dua. Hu rau rov pib dua. */.type reset_handler, %muaj nuj nqi reset_handler: // Teeb tus pointer pawg mus rau qhov kawg ntawm pawg. // Tus nqi '_estack' tau hais tseg hauv peb kab ntawv txuas. LDR r0, = _estack MOV sp, r0

// Teeb tsa qee qhov dummy qhov tseem ceeb. Thaum peb pom cov txiaj ntsig no

// hauv peb qhov debugger, peb yuav paub tias peb qhov program // tau ntim rau ntawm lub nti thiab ua haujlwm. LDR r7, = 0xDEADBEEF MOVS r0, #0 main_loop: // Ntxiv 1 rau npe 'r0'. ADDS r0, r0, #1 // Loop rov qab. B main_loop.size reset_handler,.-Reset_handler

Yog li, lub zog ntawm cov phiaj xwm saum toj no yog txhawm rau ua tus qauv pom tau rau hauv ib tus tub ntxhais kawm MCU sau npe (qhov no R7), thiab nce tus nqi pib ntawm xoom rau lwm tus tub ntxhais kawm MCU sau npe (hauv qhov no R0). Yog tias peb nqis los ntawm txoj cai ua haujlwm, peb yuav tsum pom R0 cov ntaub ntawv nce ntxiv.

Yog tias koj tau ua raws nrog Cov Lus Qhia hais txog MSP432 thiab TI-RSLK chav kawm/chav sim, tom qab ntawv zoo nkauj npaum li txhua txoj haujlwm saum toj no yuav tsum paub rau koj.

Ib yam tshiab uas kuv pom tau yog kev siv "=" thaum thauj khoom "DEADBEEF" rau npe R7. Peb tsis tau siv qhov ntawd.

Cov "core. S" cov ntaub ntawv txuas ntawm no tam sim no muaj qhov ua tiav.

Kauj Ruam 8: Ua Ke Cov Cai

Nws yog lub sijhawm los ua qee yam khoom kab hais kom ua. Ib yam dab tsi tiag, thaum kawg.

Txawm li cas los xij, peb tsis nyob ntawd. Peb yuav tsum rov kho dua cov lus txib hauv kab lus, thiab hloov kho rau peb tus kheej li xwm txheej.

Nov yog tus qauv piv txwv:

npab -tsis -eabi -gcc -x assembler -nrog -cpp -c -O0 -mcpu = cortex -m0 -mthumb -Wall core. S -o core.o

Yog tias peb mus rau gnu.org qhov chaw rau GCC, (qhov xwm txheej no version 7.3),

x ib

Tus -x yog qhia cov lus. Txwv tsis pub yog tsis muaj -x, tom qab ntawd tus neeg sib tw yuav sim twv los ntawm kev siv cov ntawv txuas ntxiv. (hauv peb qhov xwm txheej, *. S).

Qhov piv txwv saum toj no los ntawm tsab xov xwm qhia meej txog kev sib sau ua ke-nrog-cpp, tab sis peb tsuas yog tuaj yeem ua cov khoom sib dhos.

c

Tus -c hais tias suav tab sis tsis txuas.

Oj 0

Qhov -O yog teeb tsa qib kev ua kom zoo. Siv -O0 (oh -zero) hais tias "txo lub sijhawm sib sau thiab ua kom debug tsim cov txiaj ntsig xav tau. Qhov no yog lub neej ntawd".

mcpu = cortex-m0

-Mcpu qhia lub npe ntawm tus txheej txheem phiaj. Hauv peb qhov xwm txheej, nws yuav yog cortex-m4.

hmob

-Mthumb qhia meej xaiv ntawm kev tsim cov cai uas ua rau ARM thiab THUMB xeev.

Txhua

-Wall yog qhov tseeb heev thiab paub zoo. Nws tig rau txhua tus chij ceeb toom.

Thaum kawg, qhov kawg ntawm qhov hais kom ua peb muaj cov ntaub ntawv nkag mus core. S thiab cov ntaub ntawv tso tawm core.o.

Nov yog qhov ua tiav kab lus txib tshiab kom haum rau peb cov ntaub ntawv tshwj xeeb.

npab -tsis -eabi -gcc -x assembler -c -O0 -mcpu = cortex -m4 -mthumb -Wall core. S -o core.o

Thiab uas suav.

Kauj Ruam 9: Txuas Txoj Haujlwm

Ncaj nraim los ntawm qhov piv txwv hauv kab lus, peb muaj qhov no:

arm -none -eabi -gcc core.o -mcpu = cortex -m0 -mthumb -Wall --specs = nosys.specs -nostdlib -lgcc -T./STM32F031K6T6.ld -o main.elf

Feem ntau ntawm cov saum toj no koj tau pom. Hauv qab no yog yam tshiab.

specs = nosys.specs

Qhov no yog qhov nyuaj me ntsis los piav.

Nws tau ua nrog "semihosting" thiab "retargeting", thiab nws tau ua nrog cov tswv yim / tso tawm. Nws kuj tseem ua nrog kev hu xov tooj thiab cov tsev qiv ntawv.

Feem ntau, cov txheej txheem teeb tsa tsis muab cov txheej txheem nkag/tso tawm. Qhov no yuav cuam tshuam rau cov kab ke lossis tsev qiv ntawv hu (piv txwv: printf ()).

Semihosting txhais tau tias debugger (saib Kauj Ruam 11 duab nrog debugger ib puag ncig liab) muaj cov channel tshwj xeeb thiab siv cov txheej txheem semihosting, thiab koj tuaj yeem pom qhov tso tawm ntawm printf () ntawm lub tshuab host (ntawm lub debugger).

Retargeting, ntawm qhov tod tes, txhais tau tias cov tib lub system lossis cov tsev qiv ntawv hu tau txhais lwm yam. Lawv ua lwm yam, uas ua rau muaj kev nkag siab rau cov kab ke. Hauv qhov kev nkag siab, hais rau printf (), muaj qhov ua tiav tshiab, rov ua tiav ntawm kev ua haujlwm ntawd.

Tau hais txhua qhov ntawd, --specs = nosys.specs txhais tau tias peb yuav tsis ua ib nrab hosting. Qhov ntawd ib txwm txhais tau tias peb tab tom rov qab los. Qhov ntawd coj peb mus rau tus chij tom ntej.

nostdlib

Qhov kev xaiv txuas -nostdlib yog siv los txuas qhov haujlwm uas xav ua kom nyob ib leeg. -nostdlib cuam tshuam txog kev xaiv tus kheej -nodefaultlibs thiab -nostartfiles. Hauv qab no peb tham txog ob txoj kev xaiv cais, tab sis kev siv feem ntau tsuas yog nostdlib rau ib-nres kev yuav khoom. Thaum txuas cov phiaj xwm phiaj xwm, txheej txheem cov tsev qiv ntawv xws li libc tau txuas los ntawm lub neej ntawd, muab txoj haujlwm nkag mus rau txhua tus qauv kev ua haujlwm (printf, strlen thiab phooj ywg). Qhov linker xaiv -nodefaultlibs disables linking nrog cov default library tsuas yog cov tsev qiv ntawv txuas nrog yog cov uas koj hais meej lub npe rau tus txuas txuas siv -l tus chij.

lwg

libgcc.a yog lub tsev qiv ntawv txheem uas muab cov subroutines sab hauv kom kov yeej qhov tsis txaus ntawm cov tshuab tshwj xeeb. Piv txwv li, tus txheej txheem ARM tsis suav nrog kev qhia faib. ARM version ntawm libgcc.a suav nrog kev faib ua haujlwm thiab tus sau tau tso tawm hu mus rau qhov haujlwm uas xav tau.

T

Nov tsuas yog ib txoj hauv kev los qhia rau tus neeg txuas kom siv cov ntawv no ua cov ntawv txuas. Hauv peb qhov xwm txheej, lub npe ntaub ntawv yog linker.script.ld.

o main.elf

Thaum kawg, peb qhia tus txuas txuas yuav lub npe ntawm cov ntaub ntawv tso tawm zaum kawg uas yuav raug hlawv/flashed rau hauv peb lub cuab yeej.

Nov yog peb cov kab lus ntawm kab lus hais kom ua tiav, hloov kho rau peb qhov xwm txheej tshwj xeeb:

arm -none -eabi -gcc core.o -mcpu = cortex -m4 -mthumb -Wall --specs = nosys.specs -nostdlib -lgcc -T./linker.script.ld -o main.elf

Peb paub tseeb tias cov ntawv sau, thiab cov ntaub ntawv core.o, yog ob qho tib si hauv cov npe, qhov twg peb yuav ua kab lus hais los saum toj no.

Thiab nws txuas nrog tsis muaj teeb meem.

Ib daim tshev

Peb mam li khiav:

npab-tsis-eabi-nm main.elf

thiab peb tau txais:

devchu@chubox: ~/Kev Txhim Kho/Atollic/TrueSTUDIO/STM32_workspace_9.1 $ arm-none-eabi-nm main.elf 20014000 A _estack 08000010 t main_loop 08000008 T reset_handler 08000000 T vtable

Zoo zoo. Lub caj npab-tsis-eabi-nm hais kom ua yog txoj hauv kev teev cov cim hauv cov khoom siv.

Kauj Ruam 10: Xeem Kev Sib Txuas rau STM32 Nucleo-64

Kev Ntsuas Kev Sib Txuas rau STM32 Nucleo-64
Kev Ntsuas Kev Sib Txuas rau STM32 Nucleo-64
Kev Ntsuas Kev Sib Txuas rau STM32 Nucleo-64
Kev Ntsuas Kev Sib Txuas rau STM32 Nucleo-64

Koj thawj lub hom phiaj, yog koj yuav tsum xaiv los lees nws, yog kom tau txais koj li kab ke kom pom koj li kev txhim kho.

Siv Windows

Rau Windows, Kuv txiav txim siab teeb tsa TrueSTUDIO los ntawm Atollic (pub dawb version). Nws yog qhov tsis muaj teeb meem teeb tsa thiab nws tau teeb tsa tus tsav tsheb yog li kuv tuaj yeem siv st-txuas los ntsuas qhov kev sib txuas. Thaum kuv tau teeb tsa TrueSTUDIO thiab tus thawj tswj xyuas lub cuab yeej pom lub cuab yeej, Kuv tau rub cov cuab yeej texan/stlink qhia los ntawm Bare Metal tsab xov xwm peb tau ua raws. Kuv rov tso daim nplaub tshev ncaj qha rau hauv "C: \", thiab rov tsim qee qhov txuas los ntawm kuv lub zos cygwin lub tsev tso rau hauv cov lus txib.

ln -s /c/STM32. MCU/stlink-1.3.0-win64/bin/st-info.exe ~/bin/st-info

Raws li kev sim thawj zaug los saib seb peb puas tuaj yeem sib txuas lus nrog lub cuab yeej, Kuv tau khiav:

st-info-sojntsuam

Thiab tau rov qab:

Pom 1 stlink programmers

Yog li tam sim no peb paub peb tuaj yeem tham/nug peb pawg tswj hwm kev txhim kho.

Siv Linux

Rau linux, koj tsis tas yuav xav tau tus tsav tsheb. Tab sis rau Debian, koj yuav tsum tsim cov cuab yeej st los ntawm qhov chaw.

git clone

Nco ntsoov tias koj tau nruab libusb-1.0-0-dev.

apt npe | grep -E "*libusb.*dev*"

Koj yuav tsum pom:

libusb-1.0-0-dev/xenial, tam sim no 2: 1.0.20-1 amd64 [teeb tsa]

los yog tej yam zoo li ntawd.

Txhawm rau nruab nws:

sudo apt-tau nruab libusb-1.0-0-dev

Nco ntsoov tias cov lus saum toj no tsis zoo ib yam li:

sudo apt-tau nruab libusb-dev

Qhov tseeb ploj lawm libusb dev tuaj yeem ua rau cmake muaj teeb meem.

CMake Yuam Kev: Cov ntsuas hauv qab no tau siv hauv txoj haujlwm no, tab sis lawv tau teeb tsa rau NOTFOUND.

Hloov mus rau cov npe hauv paus ntawm txoj haujlwm (… blah /blah /stlink). Ua ib qho "ua tso tawm".

Tom qab ntawd tsim, cov cuab yeej yuav tsum nyob hauv qab ".. /build /Release".

Koj tuaj yeem khiav "st-info-probe". Nov yog qhov tso tawm nrog Nucleo txuas nrog, tom qab ntawd tsis yog.

devchu@chubox: ~/Kev txhim kho/stlink $./build/Release/st-info --probeFound 1 stlink programmers serial: 303636414646353034393535363537 openocd: "\ x30 / x36 / x36 / x41 / x46 / x46 / x46 / x35 / x30 / x34 / x39 / x35 / x35 / x36 / x35 / x37 "flash: 524288 (nplooj ntawv: 2048) sram: 65536 chipid: 0x0446 descr: F303 cov cuab yeej siv siab devchu@chubox: ~/Kev txhim kho/stlink $./build/Release/st- info --probe Pom 0 stlink programmers devchu@chubox: ~/Kev txhim kho/stlink $

Kauj Ruam 11: Cia Peb Siv GDB Nrog Linux

Cia Peb Siv GDB Nrog Linux
Cia Peb Siv GDB Nrog Linux
Cia Peb Siv GDB Nrog Linux
Cia Peb Siv GDB Nrog Linux

Yog tias koj tau sim txhua qhov no, thiab koj tau txais qhov no deb - zoo heev! Zoo heev. Cia peb muaj kev lom zem me ntsis tam sim no.

Thaum koj yuav cov ARM kev txhim kho cov laug cam, seb lawv puas yog MSP432 Launchpad los ntawm Texas Instruments, lossis qhov no peb tab tom tham txog tam sim no, Nucleo-F303 (STM32 Nucleo-64), feem ntau lawv tuaj txog twb tau teeb nrog qhov haujlwm, feem ntau qee qhov kev pab cuam ntsais muag uas tseem suav nrog nias qhov hloov pauv tus nqi uas LED (s) nyem.

Ua ntej peb yuav nrawm dhau qhov sau ntawd, cia saib seb muaj dab tsi los saib thiab ua.

Nrog Linux, qhib lub davhlau ya nyob twg, hloov cov npe stlink git project uas peb nyuam qhuav tsim, thiab nrhiav cov cuab yeej siv.

devchu@chubox: ~/Kev txhim kho/stlink $ nrhiav. -npe st-util

./build/Release/src/gdbserver/st-util

Khiav ntawd lub cuab tam. Txij li peb twb tau dhau los sim peb qhov kev sib txuas nrog st-info-sojntsuam, peb yuav tsum tau txais qee qhov tso tawm zoo li:

devchu@chubox: ~/Kev txhim kho/stlink $./build/Release/src/gdbserver/st-util

st-util 1.4.0-50-g7fafee2 2018-10-20T18: 33: 23 INFO common.c: Thauj khoom ntaus ntawv tsis…. 2018-10-20T18: 33: 23 INFO common.c: Cov cuab yeej txuas nrog yog: F303 cov cuab yeej siv siab, id 0x10036446 2018-10-20T18: 33: 23 INFO common.c: SRAM loj: 0x10000 bytes (64 KiB), Flash: 0x80000 bytes (512 KiB) hauv nplooj ntawv ntawm 2048 bytes 2018-10-20T18: 33: 23 INFO gdb-server.c: Chip ID yog 00000446, Core ID yog 2ba01477. 2018-10-20T18: 33: 23 INFO gdb-server.c: Mloog ntawm *: 4242…

Qhov ntawd yog GDB server khiav tam sim no, thiab nws pom peb lub rooj tsav xwm txhim kho, thiab tseem ceeb dua, nws tau mloog ntawm chaw nres nkoj 4242 (qhov chaw nres nkoj pib).

Tam sim no peb tau npaj los tua cov neeg siv GDB.

Hauv Linux, qhib lwm lub davhlau ya nyob twg, sau qhov no:

npab-tsis-eabi-gdb -tui

Qhov ntawd tsuas yog tib yam li kev khiav gdb nruj hais kom ua kab, txawm li cas los xij nws hloov ua cov ntawv nyeem raws lub davhlau ya nyob twg (kuv twv yog tias nws siv cov lus foom).

Peb muaj GDB tus thov thiab GDB server khiav. Txawm li cas los xij, tus neeg siv khoom tsis txuas nrog lub server. Tam sim no nws tsis paub dab tsi txog peb Nucleo (lossis pawg thawj coj uas koj xaiv). Peb yuav tsum qhia nws. Hauv lub davhlau ya nyob twg, koj tam sim no yuav tsum yog "(gdb)". Nkag mus:

pab lub hom phiaj

Nws yuav muab ib daim ntawv rau koj. Daim ntawv ceeb toom tias qhov peb xav tau yog lub hom phiaj txuas ntxiv -nyob deb - Siv lub khoos phis tawj deb ntawm kab kab.

Tab sis peb kuj yuav tsum muab nws qhov chaw nyob. Yog li, ntawm qhov hais kom ua (gdb), sau:

(gdb) lub hom phiaj txuas ntxiv-thaj chaw hauv zos: 4242

Koj yuav tsum tau txais cov lus teb rov qab zoo li no:

(gdb) lub hom phiaj txuas ntxiv-thaj chaw hauv zos: 4242

Kev debug deb debug siv localhost: 4242 0x080028e4 hauv ?? ()

Lub caij no, ntawm lub davhlau ya nyob twg khiav st-util gdbserver, peb tau txais qhov no:

2018-10-20T18: 42: 30 INFO gdb-server.c: Pom 6 hw qhov chaw sau npe tawg

2018-10-20T18: 42: 30 INFO gdb-server.c: GDB txuas nrog.

Kauj Ruam 12: Cia Rov Ua Dua, Nrog Windows thiab Flash Peb Txoj Haujlwm

Cia Peb Rov Ua Dua, Nrog Windows thiab Flash Peb Txoj Haujlwm
Cia Peb Rov Ua Dua, Nrog Windows thiab Flash Peb Txoj Haujlwm
Cia Peb Rov Ua Dua, Nrog Windows thiab Flash Peb Txoj Haujlwm
Cia Peb Rov Ua Dua, Nrog Windows thiab Flash Peb Txoj Haujlwm
Cia Peb Rov Ua Dua, Nrog Windows thiab Flash Peb Txoj Haujlwm
Cia Peb Rov Ua Dua, Nrog Windows thiab Flash Peb Txoj Haujlwm

Cov kauj ruam los khiav st-util gdbserver, thiab caj npab-tsis-eabi-gdb tus neeg siv khoom yog qhov tseem ceeb tib yam li peb tau ua thaum Lub Sijhawm dhau los. Koj qhib ob lub davhlau ya nyob twg (cygwin, DOS cmd, lossis Windows Powershell), nrhiav qhov chaw ntawm st-util, khiav nws. Hauv lwm lub davhlau ya nyob twg, khiav ntawm caj npab-tsis-eabi-gdb tus thov kev pab. Qhov sib txawv nkaus xwb yog qhov -tui (lub davhlau ya nyob twg raws li cov ntawv pom) hom feem ntau yuav tsis txhawb.

Yog tias cov lus saum toj no ua haujlwm hauv Windows, tom qab ntawd koj yuav zaum tau tso tseg (tsuas yog tus neeg siv khoom). Txog ntawm qhov no, xyov koj yuav xav tau khiav GDB tus neeg siv qhov twg koj cov ntaub ntawv tsim yog ("core.out"), lossis ntxiv tag nrho txoj hauv kev rau cov ntawv ntawd raws li kev sib cav rau GDB tus neeg siv khoom.

Kuv ua rau kuv lub neej yooj yim los ntawm kev siv cygwin thiab tsim kev sib txuas los ntawm kuv lub zos $ HOME // bin directory rau qhov twg ntawm ob qho cuab yeej ntawd nyob.

Ok, peb tau suav ua ke thiab txuas ib yam nkaus li ua ntej, thiab peb muaj cov ntawv tseem ceeb.elf npaj kom tau flashed.

Peb muaj st-util khiav hauv ib lub qhov rais. Peb rov pib GDB cov neeg siv khoom, lub sijhawm no peb ua:

npab-tsis-eabi-gdb main.elf

Peb cia nws pib, tos rau (gdb) tam sim, ua peb cov lus sib txuas tib yam rau GDB server (st-util), thiab peb tau npaj rau nyem qhov ua tiav. Nws tiv taus huab cua heev:

(gdb) thauj khoom

Khiav nrog cygwin cov davhlau ya nyob twg, muaj qhov teeb meem paub nrog qee zaum console cov lus txib tsis tso tawm. Yog li hauv peb qhov xwm txheej, lub qhov rais uas khiav lub server tau nyob ntsiag to. Ib tus neeg siv tus neeg siv khoom, qhov twg peb tau khiav lub nra, tso tawm qhov no:

Chaw thau khoom.text, loj 0x1c lma 0x8000000 Pib chaw nyob 0x8000000, thauj khoom loj 28 Hloov tus nqi: 1 KB/sec, 28 bytes/sau.

Kauj Ruam 13: Flashing Nrog Linux - Tau Txais Ntau Ntxiv: D

Flashing Nrog Linux - Tau Txais Ntau Ntxiv: D
Flashing Nrog Linux - Tau Txais Ntau Ntxiv: D

Kauj Ruam 14: Cia Dive Me Me Deeper

Yog tias koj tuaj txog ntawm no, zoo heev. Cia peb txav mus.

Vim li cas ho tsis saib sab hauv ntawm daim ntawv tseem ceeb.elf, ua tiav? Khiav cov hauv qab no:

arm-none-eabi-objdump -d main.elf

Koj yuav tsum pom qhov tso tawm ib yam zoo li no:

main.elf: hom ntawv elf32-littlearm

Disassembly ntawm seem.text:

08000000:

8000000: 00 40 01 20 09 00 00 08.@. ….

08000008:

8000008: 4802 ldr r0, [pc, #8]; (8000014) 800000a: 4685 mov sp, r0 8000000c: 4f02 ldr r7, [pc, #8]; (8000018) 800000e: 2000 mov r0, #0

08000010:

8000010: 3001 ntxiv r0, #1 8000012: e7fd b.n 8000010 8000014: 20014000.word 0x20014000 8000018: deadbeef.word 0xdeadbeef

Dab tsi me me nuggets peb tuaj yeem tau txais los ntawm cov zis saum toj no?

Yog tias koj nco qab thaum peb tham txog thiab tsim cov ntawv txuas txuas.script.ld, peb tau hais tias cov cuab yeej ARM no muaj RAM pib ntawm 0x20000000, thiab lub cim xeeb FLASH pib ntawm 0x08000000.

Yog li, peb tuaj yeem pom tias qhov kev zov me nyuam zoo li nws txhua qhov nyob hauv FLASH nco.

Tom qab ntawd, saum toj no, tab sis tom qab Kauj Ruam, thaum peb tau hais lus tsis zoo txog "Nyob Zoo Ntiaj Teb", muaj cov lus tshaj tawm uas peb thauj tam sim, tas li, tus nqi tseeb ("0xDEADBEEF") rau hauv MCU cov ntawv sau npe ("R7").

Cov nqe lus yog:

LDR R7, = 0xDEADBEEF

Hauv peb cov cai, uas yog tib qhov chaw uas peb txawm hais txog DEADBEEF. Tsis nyob qhov twg ntxiv lawm. Thiab tseem, yog tias koj saib cov lus qhia saum toj saud/rov tsim dua, thiab lwm yam, muaj ntau qhov cuam tshuam nrog DEADBEEF dua li peb xav peb tau ua.

Yog li, tus suav sau/txuas txuas qee yam tau txiav txim siab tas li nyem tus nqi ntawm DEADBEEF rau hauv FLASH chaw nyob, ntawm qhov chaw 0x8000018. Thiab tom qab ntawd, tus sau tau hloov peb cov lus qhia LDR saum toj no los ua:

LDR R7, [PC, #8]

Nws txawm tsim cov lus tawm rau peb. Zoo nkauj npaum cas. Thiab nws qhia peb kom coj tus nqi tam sim no ntawm qhov program (lub PC rau npe), ntxiv 0x8 rau tus nqi ntawd, thiab qhov ntawd yog qhov DEADBEEF tau raug hlawv, thiab tau txais tus nqi ntawd thiab muab nws tso rau hauv R7.

Yog li ntawd tseem txhais tau tias cov phiaj xwm phiaj xwm (PC) tau taw qhia rau qhov chaw 0x8000010, uas yog pib ntawm main_loop, thiab tias DEADBEEF tus nqi nyob ntawm ob qhov chaw nyob tom qab kawg ntawm main_loop.

Kauj Ruam 15: Thaum kawg, Saib Ntsoov ntawm Txoj Haujlwm Ua Haujlwm

Txawm hais tias koj tawm ntawm GDB, tsuas yog rov hais kom ua. Koj tsis tas yuav muab nws cov ntaub ntawv; peb tsis flashing ntxiv, tsuas yog khiav nws.

Thaum koj tau rov txuas GDB cov neeg siv rau GDB server, ntawm (gdb) hais kom sai:

(gdb) cov ntaub ntawv sau npe

Koj yuav tsum pom qee yam zoo li no:

r0x0 ua

r1 0x0 0 r2 0x0 0 r3 0x0 0 r4 0x0 0 r5 0x0 0 r6 0x0 0 r7 0x0 0 r8 0x0 0 r9 0x0 0 r10 0x0 0 r11 0x0 0 r12 0x0 0 sp 0x20014000 0x20014000 lr 0xffffffff 4294967295 pc 0x8000008 0x8000008 cpsr 0x0000

Tab sis tom qab ntawd, ntawm qhov hais kom ua (gdb), sau:

(gdb) txuas ntxiv

Thiab sai sai ntaus CTRL-C. Qhov ntawd yuav tsum ncua txoj haujlwm. Nkag mus rau "cov ntaub ntawv sau npe" cov lus txib dua.

Lub sijhawm no, nws zoo li txawv:

(gdb) cov ntaub ntawv sau npe

r0 0x350ffa 3477498 r1 0x0 0 r2 0x0 0 r3 0x0 0 r4 0x0 0 r5 0x0 0 r6 0x0 0 r7 0xdeadbeef 3735928559 r8 0x0 0 r9 0x0 0 r10 0x0 0 r11 0x0 0 r11 16777216

Dab tsi tshwm sim? Raws nraim qhov peb xav tau. DEADBEEF tau thauj mus rau R7, thiab R0 tau (nrawm heev) nce ntxiv. Yog tias koj rov ua dua, koj yuav pom R0 dua nrog lwm tus nqi.

Kauj Ruam 16: Peb Xav Tsim Kev Nyeem-Tsuas Array hauv Flash

Ib txoj hauv kev los tsim qhov sib npaug ntawm cov khoom siv sib dhos thiab cov lus qhia, yog raws li hauv qab no:

.type myarray, %object // lub npe lossis daim ntawv lo 'myarray' tau txhais ua hom khoom

myarray: // qhov no yog qhov pib ntawm kev tshaj tawm ntawm 'myarray' // (nws yuav suav nrog)..word 0x11111111 // thawj tus tswv cuab lossis tus nqi muaj nyob hauv 'myarray'..word 0x22222222 // tus nqi thib ob (qhov chaw nyob sib xws)..word 0x33333333 // thiab ntxiv rau..size myarray,.-myarray // tus compiler/assembler tam sim no paub qhov twg kawg lossis // ciam teb ntawm 'myarray'.

Tam sim no peb tau teeb tsa nws hauv FLASH nco, peb tuaj yeem siv nws hauv qhov haujlwm. Hauv qab no yog ib feem:

LDR R1, myarray // qhov no thauj cov ntaub ntawv muaj nyob ntawm 1 qhov chaw ntawm 'myarray'. ' // qhov no tsis yog yam peb xav tau.

LDR R1, = myarray // qhov no thauj qhov chaw tus nqi nws tus kheej (qhov chaw nyob thib 1), // tsis yog cov ntaub ntawv.. // Qhov no yog qhov peb xav tau.

MOV R2, #0 // R2 yuav ua kom suav kom paub tseeb tias peb tsis taug kev

// kawg ntawm array. LDR R3, = myarrsize // R3 yuav yog qhov sib npaug ntawm 'myarrsize'.

// R0 yuav tuav peb cov ntaub ntawv

main_loop:

LDR R0, [R1] // Thauj cov ntaub ntawv taw qhia los ntawm R1 ('myarray') rau hauv R0. CMP R2, R3 // Puas yog peb nyob ntawm qhov txwv ntawm array? BEQ main_loop // Yog tias peb yog, peb tau ua tiav, yog li peb tsuas yog txuas mus ib txhis.

ADD R2, #1 // Txwv tsis pub, peb tuaj yeem khaws nws rov ua dua los ntawm array.

ADD R1, #4 // Ntxiv 4 txhawm rau sau npe R1, yog li nws cov ntsiab lus raug rau tom ntej

// chaw nyob..

B main_loop // Loop rov qab.

Cov vis dis aus hla txhua qhov no, thiab muaj kab laum nyob hauv. Nws zoo; nws qhia tau hais tias nws yog ib qho tseem ceeb khiav thiab debug code. Nws qhia txog rooj plaub ntawm kev taug kev tawm ntawm qhov kawg ntawm ib qho array.

Pom zoo: