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

Support for NRF arm processors #410

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft

Support for NRF arm processors #410

wants to merge 6 commits into from

Conversation

el-han
Copy link

@el-han el-han commented May 28, 2020

This is the modm part of this modm-devices RP:

modm-io/modm-devices#36

status

A minimal example compiles and blinks an LED using busy wait. I have this board:

https://www.seeedstudio.com/nRF52840-MDK-USB-Dongle-p-3184.html

I programm it with a black magic probe over SWD.

TODO

  • check if the linker file is okay. Right now it's just a copy of the sam one and I don't know much about linkerscripts
  • implement signal connections for GPIOs
  • implement UART
  • write one or more BSPs
  • extend clock module to enable multiple clock domains and select clock sources

Copy link
Member

@salkinium salkinium left a comment

Choose a reason for hiding this comment

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

You're on a very good path, very nicely done! Blinking an LED means the core stuff works fine incl. the linkerscript. I'm a little uncertain if the NRF boots at 64MHz, that seems fishy to me.

I apologize for my unreadable GPIO code, I've got a PR somewhere that cleans that up, but it's not ready yet. I suggest you just delete it, since the NRF has a much, much simpler pinmux config.

(I'll have a look at the linkerscript in more detail later, I'm currently super busy catching up on some lab work, since it opened just this week again.)

name: Examples NRF Series
command: |
(cd examples && ../tools/scripts/examples_compile.py nrf)

Copy link
Member

Choose a reason for hiding this comment

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

CircleCI gives us 4x parallelism that's why we should keep the examples running in four jobs, so that they fail quicker => faster iteration. I recommend that you rename the stm32-examples job to cortex-m-examples and add the NRF series there.

[submodule "ext/modm-devices"]
path = ext/modm-devices
url = https://github.com/modm-io/modm-devices.git
url = https://github.com/elli89/modm-devices.git
Copy link
Member

Choose a reason for hiding this comment

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

I've looked at this repo, it looks manually copied? Where from? I'm seeing a lot of linker script and so many header files it would be nice to have the some folders that structure this just a little bit (at least by family?). Preferrably automated via update.py similiar to the other cmsis-header repos to simplify maintenance.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, never mind, I just looked at the top-level nrf.h file and it looks like it is not meant to be split apart by family. Let's keep this in mind as a future goal, currently this copies all family files, which is unfortunate.

namespace modm::platform
{
uint16_t modm_fastdata delay_fcpu_MHz(64);
uint16_t modm_fastdata delay_ns_per_loop({{ loops * 1000 / 64 }});
Copy link
Member

Choose a reason for hiding this comment

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

The core runs at 64MHz right after boot? This should be set to the default clock frequency which is probably much less than 64MHz.

HighFrequencyClockController::updateCoreFrequency()
{
delay_fcpu_MHz = Core_Hz / 64'000'000;
delay_ns_per_loop = ::round({{loops}}000.f / (Core_Hz / 64'000'000));
Copy link
Member

Choose a reason for hiding this comment

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

divide by 1MHz.

SCB->CPACR |= (3UL << 20) | (3UL << 22);
__DSB();
__ISB();
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Already done by modm startup.

CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Serial << CLOCK_TRACECONFIG_TRACEMUX_Pos;
NRF_P1->PIN_CNF[0] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Would probably be implemented in :platform:itm, but on STM32 the pins could only be configured by the debugger. Let's deal with this later.

NRF_P0->PIN_CNF[12] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
NRF_P0->PIN_CNF[11] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
NRF_P1->PIN_CNF[9] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Definitely requires debugger support and not supported by modm currently.

while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NVIC_SystemReset();
}
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Should probably be moved out of startup and into a modm::platform function or class. Seems a bit harsh with the SystemReset during system boot.

while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NVIC_SystemReset();
}
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@rleh rleh added the stale ♾ label Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants