-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start MicroBit v2 support #385
base: master
Are you sure you want to change the base?
Conversation
Hi Fabien, thanks for this commit. I noticed that several functions were not implemented yet such as only addressing the port 0.x range, display, IMU, touch logo, pin assignment with breadboard expansion, ADC, PWM. I have implemented them in my repo and if you want I can send a PR https://github.com/aiunderstand/ADA_Drivers_Library. I am in the process of converting the working (but commented out) examples in the Text_Scrolling project into separate examples like you did with the V1. Unfortunately that is not all that is needed to make it work with the internal hardware debugger. GNAT studio is using an old PyOCD version, so I have to instruct my students to install Python (with path added to environment!) and pip install pyocd to install the latest version. That one supports the nRF52833 used in the Microbit v2. For last years class I ported the Arduino Nano BLE Sense based on the nRF52_DK (not shared yet as it needs polishing) and that required a newer version of PyOCD as well because it misses J-Link support in the 0.25 version. We also had to create custom debug shield to make debugging with J-link possible, so I was happy to see you started the Microbit V2 port. Finally, do you know how to force upload a binary using GNAT studio? When students have a brand new microbit v2 and successfully compiled a .bin they cannot upload it the first time, with the tool complaining it cannot erase sectors (see screenshot). You have to manually upload it by dragging and dropping the .bin to your Microbit drive. After you have done that once, you can use GNAT studio to upload .bin like normal. Thanks! |
Just as a heads-up: most microbitv1 examples have now been ported to v2, the internal speakers works and is set as the default output in the music example. The servo and ble beacon example also work. As an ADA novice, I am now exploring tasking and the ravenscar profile. I have added the nrf52833 to the bb-runtimes repo, so I can run .\build_rts.py --output=C:\GNAT\2021-arm-elf\arm-eabi\lib\gnat --build nrf52833 -v --force. Is there a standard ravenscar-full and ravenscar-sfp test that I can run to see if the implementation is correct? I basically copied the settings from the nrf52840, checked the nrf52833 manual on the register and interrupt table and added the port 1.x base address and various missing interrupt vectors (eg. in handler.s), updated flash/ram in the memory map. I also created new ravenscar profiles (see https://github.com/aiunderstand/ADA_Drivers_Library/tree/master/boards/MicroBit_v2) based on the zfp profile but removed the crt0.s and link.ld. Is this the right approach or should I generate these profiles from bb-runtimes or something entirely different? Thanks |
Link to fork of bb-runtimes and rough attempt to implement nrf52833 https://github.com/aiunderstand/bb-runtimes |
That's great @aiunderstand 👍 If you want to open a pull-request on this repo you have to fork using the GitHub interface and not create a new repo from scratch like you did.
You can start with a basic loop: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Real_Time; use Ada.Real_Time;
procedure Main is
begin
loop
Put_Line ("Hello");
delay until Clock + Seconds (1);
end loop;
end Main; |
|
For 2) See pyocd/pyOCD#1212 |
For 3) Small update. I found out that in setup_board.adb the LFLCK was defined as an external clock source, which the micro:bit v2 does not have, hence it was only running when I was running it via debug mode (using the clock of the KL27Z). Changing it to "RC" runs the basic loop example. I have updated https://github.com/aiunderstand/bb-runtimes for inspection. In the next commit I will base the changes on the SVD2ADA repo. As I am new to ADA and ADL i'd like some feedback on how to continue. My goal is to make the ZFP examples, so the basic capabilities of the board, work with ZFP/Light, Ravenscar and Jorvik.
0x0000460c in __gnat_irq_trap () . The other setup is by clicking in GNAT on New Project and selecting the Scrolling Text demo. This template uses the ravenscar-sfp-microbit profile and does not depend on the microbit ZFP board directory, but rather on a minimum set of files to support main.adb. This template can switch to ravenscar-full-microbit but also cannot switch to zfp-microbit. Any idea why the zfp-microbit profile does not work in both microbit v1 setups? Does zfp startup code require different startup and linking code than ravenscar/jorvik? If so, any documentation to point to? I dont plan to do much with MicrobitV1 as its flash memory is too small for ravenscar profiles, so it is mostly for understanding.
Thanks for all the help! |
Hello @aiunderstand, I did all the preparation work for the micro:bit v2 in this pull-request, I highly recommend that you start from this. It uses The only thing that you have to focus on is the content of this folder: https://github.com/AdaCore/Ada_Drivers_Library/tree/master/boards/MicroBit/src that you have to copy and adapt for the micro:bit v2 (except for Cheers, |
Hi @Fabien-Chouteau , I started from that repo, see the OP. I managed to to get the ravenscar and jorvik profile to work, see my comment on Sep 24th. I based my latest commit on SVD2ADA and the nrf52833.svd and updated the bb-runtimes and ADL accordingly. I created a ravenscar example directory for the microbit 2 to show that the timing is accurate with delay and delay until (in case of jorvik). I still have 3 questions left from above:
|
In bb-runtimes the startup code for ZFP and Ravenscar is the same.
Besides some indentation issues, the Delay_Ms function should not use the assembly "wait for interrupt" instruction: https://github.com/aiunderstand/Ada_Drivers_Library/blob/db0e7eedf5ec5b2bd43f4e146c3d50ba57cd05a6/boards/MicroBit_v2/src/full/microbit-timewithrtc1.adb#L15 Since you have Ravenscar available, you should use protected entries to stop a task until an event occurs: Also, there is already an implementation of
About Ravenscar vs ZFP, it's ok to pick only one and make that the supported run-time. It looks like Ravenscar is important for you so you can focus on this and forget ZFP. |
Thanks for the reply @Fabien-Chouteau. In the next few months I will spend some development time on polishing my work for a PR. This should enable full v2 support incl ravenscar and zfp, various drivers such as radio, adc, pwm, gpio 1.x and many examples. My students had great fun with these features last year and build interesting robot projects and applications, as well learn a thing or two about timing analysis and tasking in practice. With regards to your feedback some follow-up questions:
Sure, in cortexm.py the startup-rom, handler and linker code is the same for all three runtimes for the microbit V1 board but the generated runtime for zfp (zfp-microbit) does not work while zfp-cortex-m0 based on crt0 and link.ld does work. Take for example the Microbit V1 scrolling_text example from the ADL and change the runtime from zfp-cortex-m0 to zfp-microbit. Only with the zfp-microbit runtime will it report the error mentioned above as soon as an interrupt is used (eg the init code of microbit-time using RTC1). Both the linker code and startup code are quite similar but not exactly the same between the two runtimes. Is there a bug in zfp-microbit?
Thanks this is exactly what I needed to learn.
Yes Ravenscar is important for the course, but usually I start with the basics and thus with ZFP. I will fork this repo and add a ravenscar-full (jorvik) and zfp (light) category for the examples and boards since they are so fundamentally different (eg. language features, drivers using ada.real-time). |
Awesome @aiunderstand, can't wait to see the results :) |
@Fabien-Chouteau just as a heads-up: I added I2C support for external I2C devices and a new motor driver for 4 wheel drive project (the DFR0548). Three notes:
Start, h80 [ h40 | WR ], h00, h00, While I expect something like Start, h80 [ h40 | WR ], h00, h00, Stop There is no argument to the procedure in the low level TWI package to change the repeated stop condition. Should the repeated stop condition be made explicit like in codal v2 or is there a reason to keep that option hidden? It certainly works for communicating with the internal IMU or with devices that don't do fancy tricks like auto-increasing the address every time a byte is received.
|
It's great to have the two separated. What I would do is to not expose the internal I2C at all. You can declare it in the private part of the
Indeed there is a problem here. We don't expect the R/W bit in the address. There has been discussions on this and the problem is that changing the behavior will break everything that is working so far...
Again I think this is a question of what API HAL.I2C should be expose. |
No description provided.