Getting Started with Multicore Programming on the Raspberry Pi Pico

  Переглядів 42,660

Learn Embedded Systems

Learn Embedded Systems

День тому

This video covers how to create a simple multicore program which uses both cores on the Raspberry Pi Pico. We use a Visual Studio Code project to program the brand-new Raspberry Pi Pico microcontroller board. We created a program where one core uses the analogue to digital converter in the Pico to read the internal temperature of the RP2040 and sends this data to another core to output the temperature of the chip to a windows machine over a USB serial interface.
This video provides a conceptual overview of multicore (dual core) operation on the Raspberry Pi Pico. It also explains how to configure interrupts to correctly handle the sending and receiving of data between cores. We briefly discuss how to set up the analogue to digital converter (ADC) to read the onboard temperature of the RP2040 chip.
The source code for this project (and a written article version) is available here: learnembeddedsystems.co.uk/ba...
Timestamps
00:00 - Introduction
00:33 - Why use a Multicore Program?
01:46 - How do Multicore Programs Work?
03:40 - Creating a Visual Studio Code Project
04:29 - Writing CMakeLists File
05:30 - Writing C File
09:45 - Conclusion
If this video helped you, please consider leaving a like and subscribing, thank you!
To see my other videos on the Raspberry Pi Pico, check out the playlist here: • Pico Tutorials
You can find more embedded systems tutorials and projects on my website learnembeddedsystems.co.uk
-- Equipment I use regularly --
The following links are affiliate links where I may make a small percentage on qualifying sales through these links. Use the respective UK or US links listed.
Budget Soldering Iron: UK: amzn.to/3pQpvUu US: amzn.to/3bBawIJ
Breadboards: UK: amzn.to/3solZCe US: amzn.to/3dGsHiS
Jumper Cables: UK: amzn.to/37JfToi US: amzn.to/3r384S9
Camera: UK: amzn.to/3qKLwFr US: amzn.to/3pK0V7C
Lens: UK: amzn.to/380lQxp US: amzn.to/3knH3WL
Tripod: UK: amzn.to/37H0Nzw US: amzn.to/3byKHsV
All videos and tutorials on this channel and mentioned websites are for educational purposes only.

КОМЕНТАРІ: 79
@MikeSims70
@MikeSims70 2 роки тому
Hands down the BEST coding video I've ever seen. Your narrative keeps up perfectly with your coding, you explain everything perfectly and you don't have any time-wasting moments in the video where EVERYONE ELSE DOES because they think that we want to sit here and watch them correct their mistakes while they mumble to themselves. NOT YOU! You NAILED IT! NICE WORK!
@a1nelson
@a1nelson 2 роки тому
Agreed. It’s very nicely put together. Controllers Tech videos are also packed with useful info and presented well. (Not everyone will appreciate the presenter’s artificial voice, but the quality content and thoughtful presentation make them worth a look.)
@McTroyd
@McTroyd 3 роки тому
Short, straightforward, to-the-point. I like it. Thanks! 👍
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Glad it was helpful!
@willitmicrowave6207
@willitmicrowave6207 3 роки тому
This is exactly what I was looking for
@ethanspitips5903
@ethanspitips5903 3 роки тому
Great video!! Very informative with how cores work and how to get things working. Nice work!
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Thanks for the support! Glad you it informative!
@realwmm
@realwmm 11 місяців тому
Nice intro. Thank you.
@lusiaa_
@lusiaa_ 3 роки тому
Wow, what a nice channel, I'm glad I found it! This video was super helpful
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Thank you! Glad it was helpful!
@jugshangar573
@jugshangar573 8 місяців тому
Thanks for doing this in C/C++. There are copious amounts of micropython examples out there for the Pico, but very few useful ones in C/C++. Nice pacing, editing and focus.
@LearnEmbeddedSystems
@LearnEmbeddedSystems 7 місяців тому
Thank you! We will focus on C mostly with this channel!
@spotterinc.engineering5207
@spotterinc.engineering5207 3 роки тому
Great video. It would be helpful if you used a larger font on VS Code or encoded the video at a higher bit rate so the text was more readable. Thanks.
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Thanks for the feedback David, I will be sure to fix this in my upcoming videos!
@jyvben1520
@jyvben1520 3 роки тому
yeah, stopped viewing just listening, video text too small, website is fine
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
@@jyvben1520 Thank you for the feedback, still new to this tutorial/youtube game so very useful to know how to improve! I have already increased the font size in my upcoming videos. Happy to hear you found the website useful!
@MagicPlants
@MagicPlants 3 роки тому
I thought the text size was just fine but the bright white backgrounds of the animations were blinding, maybe a texture a dark mode style would be better? Awesome video.
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
@@MagicPlants Thank you for your feedback, I will look into creating a darker theme for my new videos! Much appreciated :)
@bern047
@bern047 3 роки тому
Excellent video, thanks I will keep following
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Awesome, thank you!
@manishpoudel4540
@manishpoudel4540 3 роки тому
keep it up man nice work real helpful thank you
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Thank you! Glad I could help
@edwardvidal6176
@edwardvidal6176 2 роки тому
Another great video. I did have to add sleep_ms(1000); after stdio_init_all(); in main to get the program to function correctly. I am looking forward to seeing multi core with the freeRTOS. Thanks!
@lumpyfishgravy
@lumpyfishgravy 3 роки тому
Thanks. In 25 years of firmware coding I always assumed I'd need multithreading at some point but it just hasn't happened; PC software's a different matter of course. So I come to the Pico wondering what scenarios justify the overhead. Most multicore MCUs have cores specialized for different purposes - eg M0/M4 - which makes sense. I'm thinking it's gonna need some careful design to get the most out of two symmetrical cores. But they're welcome!
@adamreynolds1541
@adamreynolds1541 3 роки тому
Thanks for the video. What is the size of the FIFO buffer?
@villehallivuori5536
@villehallivuori5536 3 роки тому
Is there a race condition between checking queue status and clearing the queue interrupt?
@smartinc1397
@smartinc1397 2 місяці тому
Very nice =) Thanks =)🙂
@Timh-hx2le
@Timh-hx2le 3 роки тому
Although I have now Pico, I found it realy interesting!!
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Glad to hear that you found this video interesting!
@Hacker-at-Large
@Hacker-at-Large 3 роки тому
Interesting illustration, but normally you’d want to do the bare minimum in an interrupt handler, and defer calculations and printing to a foreground task on the same core.
@danman32
@danman32 3 місяці тому
I'm surprised you didn't get a watchdog exception for doing so much during an interrupt, unless the Pico SDK doesn't check for that. For the ESP32, if you spend too much time in an interrupt, you'll get a panic and crash. That happened to me trying to use an interrupt handler in ESP32 to process data when available from an external ADC that calculates AC RMS from a current sensor. A better method of handling data transfer signaled by an interrupt is to tell the main program in core1 through a flag that there's data available, or have the interrupt populate a buffer defined in the core1 code. But I realize this is just to get our feet wet using multi-core, FIFO, and interrupt.
@Kefford666
@Kefford666 3 роки тому
Super interesting! Nice to see the whole project being created too rather than just opening Arduino IDE. Although I’m guilty of that I suppose as I just let CubeMX do all the setup 😝 How have you found the discoverability with the pi pico? Is all of this based on examples they provide and is it easy to dig into the HAL files and find what you need or is it provided as a compiled library that you can’t view?
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
The Pico c/c++ SDK is pretty well documented, and so most of the examples I present in these videos will follow a similar form to the examples so people can jump from these videos into the documentation and vice versa. I will have a few videos (soon-ish) not using the SDK. In terms of discovery, you can poke around the HAL (or SDK as RPi foundation like to call it) all you like, it is not compiled until you compile it, but finding what you are looking for may take a little time. You can have a look at the Github here: github.com/raspberrypi/pico-sdk
@VasaMusic438
@VasaMusic438 3 роки тому
super!!!!!
@KamiMountainMan
@KamiMountainMan Рік тому
Is it possible to simulate multithreading on core1(or even core0) by changing and switching between the interrupt handlers?
@taiwo7840
@taiwo7840 Рік тому
It would have been helpful if you also show how your temperature sensor was connected to the Pico
@eminberkunal3919
@eminberkunal3919 Рік тому
I have a question. How can you send the value of a variable that has been defined in the core1 back to core0? I've been trying to send the temp variable calculated in the core1 back to the core0 with the "multicore_fifo_push_blocking(temp);" function but it doesn't appear to be working.
@fabiusIII
@fabiusIII Рік тому
In my experience one should never do blocking calls directly in interrupt handlers.
@xuxusito
@xuxusito 3 роки тому
Can you please make a video on how to make sure that a specific thread is executed in hard real-time? For example a time of 54 micro seconds? How can this be achieved? With a condition variable?
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Precise timing will require a real time operating system (RTOS). There has already been a port of freeRTOS to the Pico, and I will eventually get round to making a video on it! If you can't wait then here is a link to the freeRTOS port github.com/PicoCPP/RPI-pico-FreeRTOS
@brian2007tube
@brian2007tube 3 роки тому
What would the micropython code for this be?
@lottalava
@lottalava 2 роки тому
would be nice to see how to use pico with linux developing and FreeRTOS
@mohdrais5908
@mohdrais5908 3 місяці тому
Hello, I do not understand the conversion factor : const float conversion_factor = 3.3f/(1
@talk2azs
@talk2azs 3 роки тому
I have my dev machine set up exactly the same way as "Learn Embedded Systems" The issue I am having with setting up the multi-core is that I am getting errors during the CMake configuration process. I get the following errors: [cmake] TinyUSB available at C:/Pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; adding USB support. [cmake] Compiling TinyUSB with CFG_TUSB_DEBUG=1 [cmake] -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) [cmake] CMake Error at C:/Pico/pico-sdk/src/rp2_common/pico_stdlib/CMakeLists.txt:26 (set_target_properties): [cmake] set_target_properties Can not find target to add properties to: multicore [cmake] Call Stack (most recent call first): [cmake] CMakeLists.txt:18 (pico_enable_stdio_usb) [cmake] [cmake] [cmake] CMake Error at C:/Pico/pico-sdk/src/rp2_common/pico_stdlib/CMakeLists.txt:22 (set_target_properties): [cmake] set_target_properties Can not find target to add properties to: multicore [cmake] Call Stack (most recent call first): [cmake] CMakeLists.txt:19 (pico_enable_stdio_uart) [cmake] [cmake] [cmake] ELF2UF2 will need to be built [cmake] -- Configuring incomplete, errors occurred! [cmake] See also "C:/Pico/pico-projects/build/CMakeFiles/CMakeOutput.log". [cmake] See also "C:/Pico/pico-projects/build/CMakeFiles/CMakeError.log".
@MultiCraftTube
@MultiCraftTube 3 роки тому
Two cores should be nice for DSP or audio analysis. One core reads ADC and one performs FFT.
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
That is a perfect example of off-loading a more demanding task onto the second core! I will look into this and perhaps make a video of your example
@MultiCraftTube
@MultiCraftTube 3 роки тому
@@LearnEmbeddedSystems Nice! Maybe share your code if the video is online? ;D
@BrianG61UK
@BrianG61UK 2 роки тому
Would reading the ADC directly take more CPU than reading from the FIFO? I wouldn't have thought it would.
@TooSlowTube
@TooSlowTube 3 роки тому
Can it be done with the Arduino IDE too, or are we limited to one core?
@TooSlowTube
@TooSlowTube 2 роки тому
Answering my own question; earlephilhower's arduino-pico, on github, allows the use of both cores. You have the normal setup() and loop() for core 0, and an optional setup1() and loop1(), for core 1. You can install support from there, or by copying the .json link into the settings of the Arduino IDE, then use the Boards Manager, on the Tools->Board menu. Posting the link got my comment blocked, so you'll have to google it, or search on github.
@RiverMersey
@RiverMersey 3 роки тому
How possible i would it be to use picos in a computing cluster?
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
I think it would certainly be possible but it's actual use might be quite limited. These microcontrollers perform well performing fast functions like I/O but don't have particularly much compute horsepower. So as an exercise it would certainly work but in terms of functionality? I think it would be outperformed by the most basic Raspberry Pi cluster. Hope this helps!
@blahblah-im5sk
@blahblah-im5sk 3 роки тому
Good video, but i confused , how can we talk about a multi-core application if there is an external controller (or interrupt)? You can't do two operations at once if you have a controller or loop .In my opinion, a serial processor cannot operate two operations independently of each other. If it's working, *it doesn't return any data to you.* anyway, thanks for sharing, have nice day !
@klh_io
@klh_io 2 роки тому
The interrupt was set on Core 1, so it won't have any effect on Core 0. You *can* do two operations at once *if you have two cores* - that's the point of having multiple :D
@thomasflaherty5509
@thomasflaherty5509 2 роки тому
Why would you use the FIFO buffer when you can just use global variables?
@BrianG61UK
@BrianG61UK 2 роки тому
The FIFOs do simply quite a wide range of possible applications. The introduction part of the video seems to rather imply the FIFO buffers are the only way to do multi-core on the Pico! Surely not?
@_--_--_
@_--_--_ Рік тому
Nice video however I would advise rather using queues and not the intercore fifos, as those are usually required to be reserved if you implement any real multicore program. Also usage of floats seems very unnecessary, fixed point would have been more than enough, especially in an ISR where you usually want to keep cycles to a minimum.
@lottalava
@lottalava 2 роки тому
what is missing with raspberry pico is a good IDE to develop with like arduino has
@dazzer_
@dazzer_ 2 роки тому
PlatformIO
@jugnu361
@jugnu361 3 роки тому
How to debug this thing ??
@BrianG61UK
@BrianG61UK 2 роки тому
That's the 64 million dollar question.
@nabilandadamslaboratory3422
@nabilandadamslaboratory3422 3 роки тому
Mate make the code bigger in the IDE; I can't see a thing.
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Thank you for your feedback - I have already implemented this in my latest (and upcoming) videos! Appreciate the feedback :)
@paulstubbs7678
@paulstubbs7678 3 роки тому
Why use dual core? The alternative is to only use half of the CPU you just paid for.
@rbphilip
@rbphilip 2 роки тому
Dude - you have a "printf" in an ISR!! it's only because this is such a trivial example that it works at all. ISRs should be short and sweet. Get the data and put it into a queue for the "main" loop for the core to handle.
@zbigniewloboda3393
@zbigniewloboda3393 3 роки тому
Your font size is too small.
@ssl666
@ssl666 3 роки тому
2:09 "Memory IS ram!"
@peter9477
@peter9477 2 роки тому
All RAM is memory, but not all memory is not RAM.
@JeromeDemers
@JeromeDemers 3 роки тому
calling a "printf" inside a interrupt handler is not really good practice. Keep is short, like raising a flag, that's it.
@BrianG61UK
@BrianG61UK 2 роки тому
It's quite surprising to me that this would work at all. I would have thought it likely that the USB output would need interrupts to work and usually interrupt systems don't, at least by default, allow interrupts to nest.
@aakashjana6225
@aakashjana6225 Рік тому
Is there a similar video but with FreeRTOS on the pico ? The ESP32 has its own slightly modified SMP enabled version of FreeRTOS i was hoping that the pico also has some such implementation Having similar function calls like the ESP-IDF for the pico would make life a lot easier to write multi-core RTOS applications. Especially with the pico W . @LearnEmbeddedSystems
#372 How to use the two Cores of the Pi Pico? And how fast are Interrupts?
14:25
RP2040 - Introduction to Assembly Language - BMA-01
25:21
Life with David
Переглядів 8 тис.
MINHA IRMÃ MALVADA CONTRA O GADGET DE TREM DE DOMINÓ 😡 #ferramenta
00:40
1 класс vs 11 класс (рисунок)
00:37
БЕРТ
Переглядів 1,4 млн
Гражданская оборона 2024 - 16 полный выпуск
1:04:15
Телеканал ICTV
Переглядів 563 тис.
когда одна дома // EVA mash
00:51
EVA mash
Переглядів 1,6 млн
The Cheapest Microcontroller? Getting started with the 10 cent Puya PY32.
21:36
Zach of All Trades
Переглядів 11 тис.
Getting started with C/C++ & MicroPython on Raspberry Pi Pico on Windows
14:14
Use BOTH Cores  |  Dual Core Programming on the Raspberry Pi Pico
7:49
Low Level Learning
Переглядів 37 тис.
Can the RP2040 output 1080p? I think so, with a little help...
10:46
#370 Raspberry Pi Pico vs ESP32 (-S2) and STM32 Blackpill
15:53
Andreas Spiess
Переглядів 382 тис.
Raspberry Pi Pico Clone with 16MB Flash, USB-C, Neopixel, and More!
8:31
How To Use A Servo With Raspberry Pi Pico
11:49
Core Electronics
Переглядів 16 тис.
Unlocking your CPU cores in Python (multiprocessing)
12:16
mCoding
Переглядів 285 тис.
MINHA IRMÃ MALVADA CONTRA O GADGET DE TREM DE DOMINÓ 😡 #ferramenta
00:40