Mecrisp-stallaris र एम्बेलो

Mecrisp-stallaris र एम्बेलो

June 22, 2022 Uncategorized 0

को साथ बाहिर जाँदैछु, म दुई दिन मात्र होइन, उद्योगको लागि मात्र देखिएकी) । म सायद तपाईंलाई सस्तो हार्डवेयरको दुई टुक्रा राख्न लगाउँदछु। यस पटक जताततै हामी त्यो हार्डवेयरमा स्थापना भएको प्रणाली प्राप्त गर्न गइरहेका छौं, र अनिवार्य “नमस्कार विश्व” र झिम्काइएको। तर त्यसपछि हामी पनि एक सुविधाहरूमा डुबकीहरू लिन सक्दछौं जुन माइक्रोकोंलीलार्रोलरमा धेरै सफा बनाउँदछ: सजिलो मसाइज।

काम गर्न!

हार्डवेयर

MECRISP-स्टिलाइसले आभासी माइक्रोकोन्ट्रोलरको ठूलो संख्यामा भाग लिन्छ, तर म्यापल मिनीको सामान्य प्रतिलिपिको रूपमा, अक्सर “STM32F103 न्यूनतम प्रणाली बोर्ड “वा” निलोदार गोली “फारम-कारक को कारण, र यो तथ्य यो छ कि त्यहाँ रातो बिक्रीको लागि प्रयोग गरिन्छ। बोर्डमा माइक्रोकोन्ट्रोलर 722 एमएचओमा सञ्चालन गर्न सक्दछ, 20 केबीको र्याम र या त 64 64 वा 128 केबीको फ्ल्याश हुन्छ। यसको प्रशस्त पिनहरू छन्, डिजिटल-मात्र व्यक्तिहरू is v v सहनशील छन्, र यसमा सबै सामान्य माइक्रोनिन्ट्रोलर परिधीय हुन्छ। यो सबैभन्दा पावर-दक्ष छैन, र यसको फ्लोटिंग-पोइन्ट एकाई वा डकको लागि छैन, तर यो एक अगायो कि यो भन्दा कम पैसाको लागि उपलब्ध छ।

प्रोग्रामर जडान, USB मा शक्ति
CATICEMPER को लागी जन उत्पादन को लागी ज्यानल उत्पादन को कार्यहरु को समान चमत्कार कि तपाईं सुरुमा चिप फ्ल्याश गर्न आवश्यक छ। ST-Lind v2 को कुनै पनि लेन एक मात्र राम्रो काम गर्दछ। (विडमय रूपमा पर्याप्त छ, प्रोग्रामर भित्र हार्डवेयर लक्ष्यमा समान छ।) अन्तमा, अन्तर्क्रियात्मक शेलमा जस्तै भाँडो आवश्यक पर्दछ भने, तपाईंलाई STM32 बोर्डमा क्रमशः जडान चाहिन्छ। त्यो सम्भवतः USB / सिरियल एडाप्टरलाई जनाउँछ।

यो सम्पूर्ण सेटअपले छिटो खाद्य खाना भन्दा धेरै खर्च गर्न गइरहेको छ, र प्रोग्रामर र युएसबी / सिरियल एडाप्टर चीजहरू हुन् जुन तपाईं जे भए पनि पहिले नै हुनुहुन्न भने, यदि तपाईं पहिले नै हुनुहुन्न भने।

तपाईं सीधा विभिन्न 333 र GD PINS मार्फत बोर्डको माध्यमबाट फैलाउनुहोस्, वा लक्षित बोर्डमा lav pla पोर्ट वा kv पिनहरू मार्फत। पछिल्लो दुई विकल्पहरू 3..3 praight praignterchipler मार्फत पास गर्नुहोस् सबै पिनहरू आपसमा मिल्दछन्, त्यसैले यो एक पटकमा एक शक्ति आपूर्ति मात्र प्रयोग गर्नुहोस्।

फर्मवेयर: अगाडि प्रणाली

Gihhub बाट सुपर-विशेष ह्याकड्यूडे-संस्करण प्राप्त गर्नुहोस्। “रोमीहरू” डाइरेक्टरीमा समावेश गरिएको एक प्राथमिक प्रणाली हो कि यहाँ डेडोको लागि काम गर्दछ। मैले [JCW] को अपर्ययनको अपर्चनीय आधारमा लोड गरेको छु। त्यहाँ धेरै धेरै पुस्तकालयहरू उपलब्ध छन्, र हामी तिनीहरूलाई अर्को पटक हेर्नेछौं जब हामीलाई आवश्यक पर्दछ।

एक बाह्य प्रणाली प्रयोग को बारे मा राम्रो कुरा यो हो कि कुनै पनि सानो समर्थन सफ्टवेयर कुनै पनि हिसाबले आवश्यक छ – अगाडि दुखाइले यसको आफ्नै कोड कम्पाइल गर्दछ, र तपाईं यसलाई क्रमिक टर्मिनल माथि अन्तर्क्रिया गर्नुहुन्छ। सबै सूक्ष्म माइक्रोन्न्ट्रोलर भित्र हुन्छ। एक अवरोध, त्यसपछि, चिप मा बाहिर निस्कदै छ। पुरानो दिनमा, यो म्यानुअल रूपमा बाइटमा घुमाउँदा गरिन्छ र र अगाडि थोरै सानो हुन्छ कि शाब्दिक रूपमा यसलाई यो तरीकाले बुटपिंग सम्भव छ। तर तपाइँ पहिले नै त्यो चिप प्रोग्रामर, हैन?

[टेक्सिन] ‘s st उपयोगिताहरू तपाईंको चिपमा बाहिर निस्कन सजिलो तरीका हो। तिनीहरूलाई github बाट डाउनलोड गर्नुहोस्, र यसलाई आफैं बनाउनुहोस् वा तपाईंको ईस्ट्रोको प्याकेज प्रबन्धकत्वको साथ तपाईंको भाग्य प्रयोग गर्नुहोस्। (विन्डोजका मान्छेहरू, तपाईं या त छोडिएका हुनुहुन्न। यद्यपि बाइनरीले केहि समय अपडेटहरू देखेको छैन, यसले गर्नेछ।)

प्रजात फेसनमा प्रोग्रामिंग तारहरू जडान गर्नुहोस्, र जादू कमाण्डहरू स्टफ-फ्ल्यास इरेज मेकर्ग-स्टिल-ह्याकराडेड-संस्करण .- पाँच सेकेन्डमा, तपाईं रम्बल गर्न तयार हुनुहुन्छ।

Gnd – gd

Swclk – clk

Swsio – dio

एक प्रोग्रामर प्राप्त गर्न को लागी एक समस्या हो यदि तपाईंसँग एक छैन भने, तर यसले तपाईंको बाँकी जीवन सजिलो बनाउँदछ, र एक प्राप्त गर्नलाई “भुक्तान” र पर्खँदै। हाम्रो आफ्नै [अल विलियकहरू] (कुनै पनि सम्बन्ध छैन) GDB को साथ डिबगिंग c वा अर्डुनो कोडको लागि हालको पोष्ट छ, त्यसैले यो तपाइँको समय यो सेट गर्न लायक छ।

सल्लो सफ्टवेयर

सिरियल हुकअप, ल्यापटप द्वारा संचालित
प्रोग्रामरलाई अहिलेको लागि राख्नुहोस् र क्रम मा STM32 मा जडान गर्नुहोस्; पूर्वनिर्धारित बौद्ध दर 11 14,200 हुनुपर्दछ। यदि तपाईंसँग अनप्लग भए पनि पावर छैन भने, तपाईंले STM32 बोर्डमा रिसेट बटन थिच्नु आवश्यक पर्दछ। यदि सबै ठीक भयो भने, तपाईं एक परिचित खोपडी-र क्रस-withes द्वारा स्वागत छ। Mecrisp लाइनहरु को अन्त्य मा एक canceed अपेक्षा गर्दै छ, त्यसैले यदि तपाईं lf + CR पठाउँदै हुनुहुन्छ भने, तपाईं सफलतापूर्वक दुई पटक मा फिर्ता प्राप्त हुनेछ।

A9 TX – सिरियल आरएक्स

A10 RX – सिरियल TX

Gnd – gd

[JCW] को रूप मा यस अनुप्रयोगको लागि बहु-प्लेटफर्मको सिमाल इमुलेटर। यसले तपाईंको सामान्य टर्मिनल कार्यक्रमले केलाई अप-एरोको साथ कमान्ड लाइन पुन: प्रविष्ट गर्न अनुमति दिदैन, जसले धेरै लामो कमाण्ड पुन: टाइप गर्नु भन्दा धेरै सजिलो हुन्छ। यो पनिautomatically includes other files, which I made substantial use of in building the binary for this article. You don’t need to run folie, but I bet you’ll like it.

नमस्कार संसार

Now it’s “Hello World” time. If you’re new to Forth, here comes an very selective introduction. type 2 2 + and hit enter. It says ok.. That’s reassuring, right? now type . (read “dot”) and it will print out the not-surprising result. dot is the first of a few global Forth shorthands that you’ll want to internalize. a lot of commands with a dot print out their results immediately. .s (dot-ess) prints out the stack contents, for instance. two a lot more idioms that we’ll see a lot of are @ for getting a variable or reading an input and ! for setting a variable or output. read these as “get” and “set” in your head when scanning Forth code.

Next, let’s see how to write a function. : starts a function definition and ; ends it. So : four 2 2 + ; defines a function that adds two and two together. (And compiles it in real time!) You can then turn around and call this function immediately. four .s will show you that our function has left the sum of two and two on the stack. In this sense, functions in Forth aren’t really functions. They don’t take explicit arguments or return explicit values. They just operate on whatever data is on the stack, and leave the results there too. That’s why Forth functions are called “words”. I’ll be sticking to this convention from now on.

Here, finally, is “Hello World”: : hw .” Hello, World!” cr ;” Strings are a little odd in Forth, mainly because of the way the language is parsed — the compiler reads up to a space and then executes what it has found, so there has to be a space between the print-a-string command (.”) and the first character that you want to print. The print command scans forward until it finds a closing “, though, so you don’t need an extra space there. cr sends a carriage return. type hw at the prompt. Hello, World!

Blinking LEDs

Even though serial text input and output is so easy in Forth, blinking an LED is the standard “hello world” of microcontrollers, so it’s time for some GPIO. because the system is already configured for this particular microcontroller board, turning an LED on is as easy as typing led.on at the prompt. want to turn it off? led.off. manual blinking will get old pretty quickly, though, so let’s write a blink word. : blink led.on 100 ms led.off 200 ms ; will do the trick. try blink blink blink. See my blink demo code for elaboration. (More on ms in a few thousand milliseconds.)

The details of the GPIO initialization are hidden in core/Hackaday/LED.fs and in Embello’s stm32f1/io.fs respectively. Digging through, you’ll see the standard initialization procedure: the particular pin is set as output by flipping some bits in the STM32’s peripheral control registers. [jcw] has defined a bunch of these, making setting a pin as output, with the push-pull driver, as easy as PC13 OMODE-PP io-mode!. (Remember the “!” indicates set the value in a variable or register.)

To configure pin PA7 for ADC input: PA7 IMODE-ADC io-mode!. testing buttons, using the built-in pullup or pulldown resistors: PA3 IMODE-PULL io-mode! and then set the output to pull up or down using true PA3 io! or PA3 ios!. You’ll then be able to read the button state with PA3 io@ (“io get”) later on.

GPIO on the STM32 chips is very flexible, and if you want to get deep into the configuration options in the datasheet, you can set all of this fairly easily using [jcw]’s io.fs code. For instance, io.all prints all of the GPIO registers and their values, which is a great help for interactive debugging. That said, there’s some room here for a a lot more user-friendly hardware-abstraction layer, if you want to contribute one.

Multitasking on the Quick

So now we’ve got a blinking LED and serial-port printing “Hello World”. Not a bad start, and both of these make good use of Forth’s interactivity: the LED only lights up when you type blink. one of the chief virtues of Forth, for me, is the ease of going between interactive testing of words like this, and then deploying the functionality in a working system. One reason is that nearly all Forths support basic cooperative multitasking. Here’s what I mean.

First, let’s loop our blink function so that we don’t have to type so much. : bb begin blink again ; creates a function, bb for “bad blink”, that will run forever. The problem with “run forever” in Forth is that you never get back to the interpreter’s command line without physically pressing the reset button, and then everything you were working on in RAM is lost.

Instead, let’s blink in a loop with a way out. : gb begin blink key? until ; creates a function that will run our blink command until there’s some input from the keyboard — the return crucial is pressed. This particular looping construct is very beneficial for testing out functions that you’d like to run continuously, without hanging the system. keep it in mind.

Once we’ve tweaked our blink function to run just the way we want it, let’s create a background task so it can blink unattended.

task: blinktask
: blink&
blinktask activate
begin blink again
;
multitask
blink&

Briefly, the task: word creates some memory space for our blinking background task that we’re calling blinktask. The function blink& does the work in the background. blink& starts off by declaring that it will use the blinktask task context, and that it must start off running. then it goes into an limitless blinking loop from which it never leaves. multitask turns multitasking on, and blink& executes our task. Run it, and the LED blinks while you can still interact with the console. Sweet. type tasks and you’ll see that there are two active: one is our blinker and the other is the interactive interpreter.

But how does the blink task know when to yield to other simultaneous processes? In Forth, the word pause yields from the current context and moves on to the next, round-robin multitasking. The ms function, among others, consists of a pause command, so what looks like a blocking delay in a single-task setup ends up playing fantastically well with your other tasks.

The great thing about cooperative multitasking is that you control exactly when there’s going to be a context switch, which can help eliminate glitches that you’ll find in preemptive systems. The downside is that you’re responsible for remembering to pause your functions now and then, and you have to verify the timing yourself. Of course, this is a microcontroller, and you have the ARM’s quite rich internal interrupt controller to play with as well.

The real point of multitasking on micros in Forth is that it makes a great workflow for writing, testing, and deploying little daemons: functions that want to be “always on”. First, write the function that does the action once. Second, test it in a loop with an escape hatch. Third, once it’s working, remove the escape and make a background task for it. You can then turn it on and off using idle and wake, even from within other tasks. See Mecrisp’s multitask.txt, the source, for a lot more details.

अब के?

So far, we’ve set up Mecrisp-Stellaris, with additional libraries from Jeelabs’ Embello Forth framework, and run some quick demos. If this has piqued your interest, I’ll take you on a walkthrough of building some real software next time. There’s a lot a lot more to say about the way that Mecrisp handles the nuances of flash versus RAM, inputs and outputs, and the practice of interactive development. some of the really freaky aspects of working in Forth will raise their funny-shaped heads, and we’ll learn to love them anyway.

In the meantime, get your cheap STM32F103 boards flashed up with our binary, and get a little bit used to playing around in the Forth environment on the chip. Blink some LEDs. look around the Mecrisp-Stellaris glossary and the embello API documentation. Or just type list to see all the command at your disposal and start hacking away.

Leave a Reply

Your email address will not be published. Required fields are marked *