Skip to content
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

Update to allow mbed and the mbed online compiler to build. #449

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

GeorgeWort
Copy link

Update to allow mbed and the mbed online compiler to build.
This allows gcc_arm, armcc, and armclang to build the DAL.

Most changes are my personal changes in order to comply with the restrictions of the up to date compilers, and are meant to give equivalent behaviour to previously.

@microbit-sam
Copy link
Contributor

Linked to:
nrf51-sdk: lancaster-university/nrf51-sdk#1
mbed-classic: lancaster-university/mbed-classic#13
microbit-dal: #449

@ghost
Copy link

ghost commented Jul 3, 2019

Not looked at the detail but I see quite a lot of files have changed and I'm wondering what regression testing has been performed / will be performed? I note the changes are "meant to give equivalent behaviour".... but would feel reassured if this had been proven. Thanks.

@martinwork
Copy link
Contributor

In places, this appears to be a development from an earlier version of the DAL. It looks like that's the only reason for the MicroBitBLEManager changes, for example.
Other files are purely white space changes.
Should we be adding .lib files? If they are necessary, maybe this should be in a branch or fork repo.
Will it still compile with yotta?
Why replace temporary arrays on the stack with new/delete heap allocations?
It's hard to make out what the essential changes are.

@@ -854,7 +858,7 @@ MicroBitImage MicroBitImage::crop(int startx, int starty, int cropWidth, int cro
newHeight = getHeight();

//allocate our storage.
uint8_t cropped[newWidth * newHeight];
uint8_t *cropped = new uint8_t[newWidth * newHeight];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason this and other buffers have been moved from stack to the heap?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated versions of all compilers will not allocate a dynamically sized array on the stack, expression must have a constant value. Though looking at this I have changed the type without changing how it is used, which can't be right.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the main things I would want to test thoroughly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that only on armcc5? Might be another C++11 feature.

@@ -205,7 +212,7 @@ void MicroBitQuadratureDecoder::poll()
{
NRF_QDEC->TASKS_READCLRACC = 1;
position += (int32_t)NRF_QDEC->ACCREAD;
faults = min(UINT16_MAX, faults + NRF_QDEC->ACCDBLREAD);
faults = min(0xFFFF, faults + NRF_QDEC->ACCDBLREAD);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is UINT16_MAX not provided by the other compilers? It should be part of stdint.h, no?
If not, can we check if it's not defined and define it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't appear to be for the armc5 compiler no. Where would be best to define it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top of the file I guess, we can move it somewhere else if somebody else requests it.

Sample3D centre = { 0,0,0 };
Sample3D best = { 0,0,0 };
Sample3D centre;
Sample3D best;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default constructor initialises the values to zero, but is there any specific reason to remove the {0,0,0}?
Also, to reduce the diff as much as possible, can we undo all the whitespace character changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other initializer removals. I will remove the whitespace.

@@ -59,7 +59,13 @@ DEALINGS IN THE SOFTWARE.
// A list of all active heap regions, and their dimensions in memory.
HeapDefinition heap[MICROBIT_MAXIMUM_HEAPS] = { };
uint8_t heap_count = 0;
extern "C" int __end__;
#if defined __CC_ARM || defined __ARMCC_VERSION
#define HEAP_START Image$$RW_IRAM1$$ZI$$Limit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no experience with armcc, but this is a really weird-looking and cryptic symbol, is there perhaps a better one for this value?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see this is also defined here: https://github.com/lancaster-university/mbed-classic/blob/master/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_ARM_STD/sys.cpp#L15

As weird looking at it seems, I guess it is what it is ¯\_(ツ)_/¯

packetCount = 0;
blockPacketCount = 0;
blockNum = 0;
offset = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary for the compiler compatibility?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as others.

@@ -242,6 +243,7 @@ MicroBitBLEManager::MicroBitBLEManager(MicroBitStorage &_storage) : storage(&_st
*/
MicroBitBLEManager::MicroBitBLEManager() : storage(NULL)
{
currentMode = MICROBIT_MODE_APPLICATION;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a bug fix, could you submit it as a different PR?
Same for inc/bluetooth/MicroBitBLEManager.h.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a bug fix, it is to compensate for the removal of the initializer due to Error: #321: data member initializer is not allowed from the armc5 compiler.

@@ -0,0 +1,292 @@
@ The MIT License (MIT)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the makefile needs the source/asm/CortexContextSwitch.s.gcc as well?

Right now we have two GCC asm files:

  • source/asm/CortexContextSwitch.s.gcc
  • source/asm/TOOLCHAIN_GCC_ARM/CortexContextSwitch.s

So that it can copy one of them to source/asm/CortexContextSwitch.s?
How does it decide which one of the two to copy when using GCC?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using the makefile (yotta?) it ignored the TOOLCHAIN_* directory and checks the compiler flags to copy the correct .s.gcc/armcc file to .s.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this makefile or what tool/steps generates it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
So it looks like we are manually maintaining that CMake file anyway, and in that case we can move the original GCC and ARMCC assembly files to the new location required by mbed-cli, and update these lines to find them:

if(CMAKE_COMPILER_IS_GNUCC)
file(REMOVE "asm/CortexContextSwitch.s")
configure_file("asm/CortexContextSwitch.s.gcc" "asm/CortexContextSwitch.s" COPYONLY)
else()
file(REMOVE "asm/CortexContextSwitch.s")
configure_file("asm/CortexContextSwitch.s.armcc" "asm/CortexContextSwitch.s" COPYONLY)
endif()

@@ -0,0 +1,293 @@
; The MIT License (MIT)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file meant to replace https://github.com/lancaster-university/microbit-dal/blob/master/source/asm/CortexContextSwitch.s.armcc ? If not, can CortexContextSwitch.s.armcc be moved to a subdirectory similar to this new file path pattern?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The makefile requires that file to exist there so that it can select which file to copy to asm/CortexContextSwitch.s at compile time.

uint8_t LEDDelay = 0; // power-up time for LED, in microseconds
uint32_t samplePeriod; // Minimum sampling period allowed
uint16_t faults; // Double-transition counter
uint8_t LEDDelay; // power-up time for LED, in microseconds
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these values are set in the constructor, do we need to set them here as well? If not I would rather reduce this PR as much as possible.

Copy link
Author

@GeorgeWort GeorgeWort Jul 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have set them in the constructor because I have removed them here due to the armc5 compiler error: Error: #321: data member initializer is not allowed.

BLE_API.lib Outdated
@@ -0,0 +1 @@
https://github.com/lancaster-university/BLE_API/#bbc2dc58f8da1d5a6d1882dddd5ce7399dc48889
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume these lib files are now needed for mbed-cli, is there any way around them?
If not, we now have two sources of truth, the yotta json file and these individual lib files.
What can we do to keep these in sync?
Can these lib files use git tags instead of commit hashes?

Copy link
Author

@GeorgeWort GeorgeWort Jul 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They do not need to be inside the microbit-dal repository at all, they can be in the microbit repository or pulled in manually.
I tried using a git tag and got ERROR: Named branches not allowed in .lib.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right but they have to be "somewhere", no?
If pulled manually does that mean extra steps when setting up the workspace?
I wouldn't mind having a script that parses the dependencies from the yotta json file and executes the right mbed-cli commands when setting up the workspace, what do you think the best place for a script like that would be?

Copy link
Author

@GeorgeWort GeorgeWort Jul 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhere yes.
Extra steps would be needed.
A script could extract the dependencies and use mbed add followed by mbed deploy. Best place would have to be root of this repository unless we introduce a tools directory.

@jamesadevine
Copy link
Contributor

I'm a bit nervous about most of these changes. I think these will require extensive regression tests. @jaustin

@GeorgeWort
Copy link
Author

The scope of this PR will be reduced to only include the changes required for ARMC6 compatibility.

@martinwork
Copy link
Contributor

Could the changes for each syntax compatibility issue be grouped, so we can record what syntax to avoid in the future? Maybe a separate PR for the changes needed for the build system?

error: default initialization of an object of const type 'const KeyValueTable' without a user-provided default constructor.
error: non-aggregate type 'Sample3D' cannot be initialized with an initializer list.
file(REMOVE "asm/CortexContextSwitch.s")
configure_file("asm/CortexContextSwitch.s.armcc" "asm/CortexContextSwitch.s" COPYONLY)
endif()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need to be updated to move the asm/TOOLCHAIN_GCC_ARM/CortexContextSwitch.s or asm/TOOLCHAIN_ARM_STD/CortexContextSwitch.S into asm/CortexContextSwitch.s?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yotta appears to pay attention to TOOLCHAIN_* directories, as there are plenty in mbed-classic which cause no conflicts, though I do need to modify the line below to point at the new location.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in summary, yes.

Sample3D centre = { 0,0,0 };
Sample3D best = { 0,0,0 };
Sample3D centre;
Sample3D best;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the constructor code has been reverted (was there constructor code to initialise these to 0?), shouldn't these 3 lines be reverted as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There wasn't constructor code to initialise these as they are initialised to zero by default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geowor01 I don't think there are any guarantees that struct fields are zero initialised unless they are placed in bss (globals).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesadevine The default constructor sets the value to zero.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geowor01 Ah cool 😄, my bad!

@GeorgeWort
Copy link
Author

Commits 5b015a3 and 4f1a31f are enough to allow mbed-cli to work with gcc-arm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants