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

[build] Add Makefile build script generator #557

Merged
merged 6 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ examples/**/compile_commands.json
examples/**/SConstruct
examples/**/Makefile
examples/**/generated
examples/**/coredump.txt

# repo.lb cache file
ext/modm-devices.cache
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ git clone --recurse-submodules https://github.com/modm-io/modm.git

- Efficient and fast object-oriented C++20 API.
- Support for hundreds of AVR and ARM Cortex-M microcontrollers from Atmel and ST.
- Build system agnostic: Choose SCons, CMake or use your own.
- Build system agnostic: Choose SCons, CMake, Makefile or use your own.
- Data-driven, target-specific HAL generation using the lbuild engine.
- No memory allocations in HAL with very low overall RAM consumption.
- Highly-configurable modules with sensible defaults and lots of documentation.
Expand Down
10 changes: 10 additions & 0 deletions docs/src/reference/build-systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ However, it is more optimized for terminal use and not for integration into IDEs
[See the `modm:build:scons` documentation](../module/modm-build-scons).


### Make

The `modm:build:make` generator creates a stand-alone, but feature-complete,
Makefile build system. The embedded-specific tooling is provided by wrapping
separate Python3 scripts in `.PHONY` targets. It is intended as a simple,
hackable build system without standardized IDE integration.

[See the `modm:build:make` documentation](../module/modm-build-make).


### CMake

The `modm:build:cmake` module generates a CMake build script, which you can
Expand Down
1 change: 1 addition & 0 deletions examples/avr/assert/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<module>modm:architecture:delay</module>
<module>modm:build:scons</module>
<module>modm:build:cmake</module>
<module>modm:build:make</module>
rleh marked this conversation as resolved.
Show resolved Hide resolved
</modules>
</library>
3 changes: 2 additions & 1 deletion examples/avr/display/dogm128/benchmark/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<option name="modm:target">atmega644-20au</option>
<option name="modm:platform:core:f_cpu">14745600</option>
<option name="modm:build:build.path">../../../../../build/avr/display/dogm128/benchmark</option>
<option name="modm:build:scons:image.source">images</option>
<option name="modm:build:image.source">images</option>
</options>
<modules>
<module>modm:architecture:interrupt</module>
Expand All @@ -15,5 +15,6 @@
<module>modm:processing:timer</module>
<module>modm:ui:display</module>
<module>modm:build:scons</module>
<module>modm:build:make</module>
</modules>
</library>
2 changes: 1 addition & 1 deletion examples/avr/display/dogm128/image/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<option name="modm:target">atmega644-20au</option>
<option name="modm:platform:core:f_cpu">14745600</option>
<option name="modm:build:build.path">../../../../../build/avr/display/dogm128/image</option>
<option name="modm:build:scons:image.source">images</option>
<option name="modm:build:image.source">images</option>
</options>
<modules>
<module>modm:driver:ea_dog</module>
Expand Down
1 change: 1 addition & 0 deletions examples/linux/assert/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<module>modm:architecture:assert</module>
<module>modm:debug</module>
<module>modm:build:scons</module>
<module>modm:build:make</module>
</modules>
</library>
3 changes: 2 additions & 1 deletion examples/linux/build_info/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
<options>
<option name="modm:target">hosted-linux</option>
<option name="modm:build:build.path">../../../build/linux/build_info</option>
<option name="modm:build:scons:info.build">True</option>
<option name="modm:build:info.build">True</option>
</options>
<modules>
<module>modm:platform:core</module>
<module>modm:debug</module>
<module>modm:build:scons</module>
<module>modm:build:make</module>
</modules>
</library>
3 changes: 2 additions & 1 deletion examples/linux/git/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
<options>
<option name="modm:target">hosted-linux</option>
<option name="modm:build:build.path">../../../build/linux/git</option>
<option name="modm:build:scons:info.git">Info+Status</option>
<option name="modm:build:info.git">Info+Status</option>
</options>
<modules>
<module>modm:platform:core</module>
<module>modm:debug</module>
<module>modm:build:scons</module>
<module>modm:build:make</module>
</modules>
</library>
2 changes: 1 addition & 1 deletion examples/linux/printf/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<options>
<option name="modm:target">hosted-linux</option>
<option name="modm:build:build.path">../../../build/linux/printf</option>
<option name="modm:build:scons:info.build">True</option>
<option name="modm:build:info.build">True</option>
</options>
<modules>
<module>modm:debug</module>
Expand Down
1 change: 1 addition & 0 deletions examples/nucleo_f103rb/hard_fault/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<module>modm:platform:fault</module>
<module>modm:platform:heap</module>
<module>modm:build:scons</module>
<module>modm:build:make</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/nucleo_f103rb/itm/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:build:make</module>
<module>modm:platform:itm</module>
<module>modm:processing:timer</module>
</modules>
Expand Down
19 changes: 8 additions & 11 deletions examples/nucleo_f103rb/undefined_irq/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

#include <modm/board.hpp>
#include <modm/architecture/interface/assert.hpp>
#include <string>

using namespace Board;
using namespace std::string_literals;

MODM_ISR(EXTI0)
{ MODM_LOG_DEBUG << "EXTI0 called!" << modm::endl; }
Expand All @@ -29,22 +31,17 @@ MODM_ISR(EXTI3)

[[maybe_unused]]
static modm::Abandonment
core_assertion_handler(const char * module,
const char * /*location*/,
const char * /*failure*/,
uintptr_t context)
core_assertion_handler(const modm::AssertionInfo &info)
{
if (!memcmp(module, "core\0nvic\0undefined", 19)) {
MODM_LOG_ERROR.printf("Ignoring undefined IRQ handler %d!\n", int8_t(context));
if (info.name == "nvic.undef"s) {
MODM_LOG_ERROR.printf("Ignoring undefined IRQ handler %d!\n", int8_t(info.context));
return modm::Abandonment::Ignore;
}
return modm::Abandonment::DontCare;
}
// Uncomment to ignore the assertion
// MODM_ASSERTION_HANDLER(core_assertion_handler);
// Comment this line to abandon execution
MODM_ASSERTION_HANDLER(core_assertion_handler);

// Uncomment to overwrite the undefined handler
// extern "C" void modm_undefined_handler(int32_t) {}

int main()
{
Expand All @@ -71,7 +68,7 @@ int main()
{
NVIC_SetPendingIRQ(IRQn_Type(int(EXTI0_IRQn) + ii));
ii = (ii + 1) % 5;
// wait one second for debounce
// wait for user reaction
modm::delay(500ms);
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/nucleo_f103rb/undefined_irq/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:build:make</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/nucleo_f303k8/rtos/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<module>modm:processing:rtos</module>
<module>modm:platform:heap</module>
<module>modm:build:scons</module>
<module>modm:build:make</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/nucleo_f429zi/cmsis_dsp/dotproduct/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:build:make</module>
<module>modm:cmsis:dsp:transform</module>
<module>modm:cmsis:dsp:basic_math</module>
</modules>
Expand Down
1 change: 1 addition & 0 deletions examples/nucleo_f429zi/cmsis_dsp/linear_interp/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</collectors>
<modules>
<module>modm:build:scons</module>
<module>modm:build:make</module>
<module>modm:cmsis:dsp:fast_math</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/nucleo_g071rb/custom_allocator/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<module>modm:platform:gpio</module>
<module>modm:architecture:memory</module>
<module>modm:build:scons</module>
<module>modm:build:make</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/rpi/blinky/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:build:make</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/samd/usbserial/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:build:make</module>
<module>modm:tinyusb</module>
<module>modm:processing:timer</module>
<module>modm:io</module>
Expand Down
2 changes: 1 addition & 1 deletion examples/stm32_f4ve/gui/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<extends>modm:stm32_f4ve</extends>
<options>
<option name="modm:build:build.path">../../../../build/stm32_f4ve/gui</option>
<option name="modm:build:scons:image.source">images</option>
<option name="modm:build:image.source">images</option>
</options>
<modules>
<module>modm:container</module>
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f3_discovery/usb_dfu/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:build:make</module>
<module>modm:tinyusb</module>
<module>modm:processing:timer</module>
<module>modm:io</module>
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f469_discovery/exceptions_rtti/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<modules>
<module>modm:platform:gpio</module>
<module>modm:build:scons</module>
<module>modm:build:make</module>
</modules>
</library>
4 changes: 4 additions & 0 deletions examples/stm32f469_discovery/hard_fault/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ main()
#endif
MODM_LOG_ERROR << "firmware=" << modm::hex;
for (const auto data : FaultReporter::buildId()) MODM_LOG_ERROR << data;
MODM_LOG_ERROR << "\nor\n\tmake debug-coredump";
#ifdef MODM_DEBUG_BUILD
MODM_LOG_ERROR << " profile=debug";
#endif
MODM_LOG_ERROR << "\n\n";
for (const auto data : FaultReporter())
MODM_LOG_ERROR << modm::hex << data << modm::flush;
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f469_discovery/hard_fault/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<module>modm:platform:fault</module>
<module>modm:build:scons</module>
<module>modm:build:cmake</module>
<module>modm:build:make</module>
</modules>
</library>
2 changes: 1 addition & 1 deletion examples/stm32f4_discovery/open407v-d/gui/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<extends>modm:disco-f407vg</extends>
<options>
<option name="modm:build:build.path">../../../../build/stm32f4_discovery/open407v-d/gui</option>
<option name="modm:build:scons:image.source">images</option>
<option name="modm:build:image.source">images</option>
</options>
<modules>
<module>modm:container</module>
Expand Down
2 changes: 1 addition & 1 deletion repo.lb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ from os.path import normpath

# Check for miminum required lbuild version
import lbuild
min_lbuild_version = "1.14.1"
min_lbuild_version = "1.16.0"
if StrictVersion(getattr(lbuild, "__version__", "0.1.0")) < StrictVersion(min_lbuild_version):
print("modm requires at least lbuild v{}, please upgrade!\n"
" pip3 install -U lbuild".format(min_lbuild_version))
Expand Down
8 changes: 4 additions & 4 deletions src/modm/board/samd21_mini/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ using D12 = GpioA19;
using D13 = GpioA17;

// User LED (inverted, because connected to 3V3)
using LedD13 = GpioInverted<GpioOutputA17>;
using LedTx = GpioInverted<GpioOutputA27>;
using LedRx = GpioInverted<GpioOutputB03>;
using Leds = SoftwareGpioPort< LedTx, LedRx >;
using LedD13 = GpioA17;
using LedTx = GpioA27;
using LedRx = GpioB03;
using Leds = LedTx;
Comment on lines +89 to +92
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
using LedD13 = GpioA17;
using LedTx = GpioA27;
using LedRx = GpioB03;
using Leds = LedTx;
// User LED (Rx and Tx LEDs inverted, because connected to 3V3)
using LedD13 = GpioA17;
using LedTx = GpioInverted<GpioOutputA27>;
using LedRx = GpioInverted<GpioOutputB03>;
using Leds = SoftwareGpioPort< LedTx, LedRx >;

grafik
https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/sparkfun-samd21-mini-breakout-v10.pdf

Copy link
Member Author

Choose a reason for hiding this comment

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

I know, but the problem is that the SAM GPIO implementation does not have GpioInverted or SoftwareGpioPort implemented…

Copy link
Member

Choose a reason for hiding this comment

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

Ohhh :D

Maybe we (you) should create a issue about that and add the "help wanted" label?

Copy link
Member Author

Choose a reason for hiding this comment

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

If I'm honest I would rather rework the Targets support matrix to something that's generated from lbuild using the data we already accumulate in generate_module_docs (but perhaps not so slow). That would give a much more detailed look at what peripherals are supported.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also not sure if the "help wanted" is generally useful, so far I've not seen a contributor specifically fix things they are not personally motivated to do.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is also because we hardly have such "help-wanted" problems that are suitable for beginners.
We could also try to participate in events like hacktoberfest to attract new contributors.


using Button = GpioUnused;

Expand Down
21 changes: 21 additions & 0 deletions src/modm/platform/core/avr/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ Implements the interfaces defined in the `:architecture` modules. Adds the
`-mmcu={target}` compile flag and the `F_CPU={core frequency}` define.


## Fuses

You can define the fuse values in your source code via the [`FUSES` struct ELF
section][fuses] mechanism, they are automatically used by avrdude. For fuse
values see the [AVR Fuse Calculator][fusecalc].

```c
#include <avr/io.h>
FUSES =
{
LFUSE_DEFAULT, // .low
HFUSE_DEFAULT, // .high
EFUSE_DEFAULT, // .extended
};
```


## Blocking Delay

The delay functions as defined by `modm:architecture:delay` and called with a
Expand Down Expand Up @@ -31,3 +48,7 @@ For micro- and milliseconds delays with dynamic time:
maximum time delay of 65ms for clocks larger than 6MHz, or .
- Millisecond delay is implemented fairly accurately in 1ms steps on 32-bits of
input time.


[fuses]: https://www.nongnu.org/avr-libc/user-manual/group__avr__fuse.html
[fusecalc]: https://www.engbedded.com/fusecalc/
4 changes: 1 addition & 3 deletions src/modm/platform/core/cortex/vectors.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ FunctionPointer vectorsRam[sizeof(vectorsRom) / sizeof(FunctionPointer)];
void Undefined_Handler(void)
{
%% if with_assert
int32_t irqn;
asm volatile("mrs %[irqn], ipsr" :[irqn] "=r" (irqn));
irqn -= 16;
const int32_t irqn = ((int32_t)__get_IPSR()) - 16;
// Set the currently executing interrupt to the lowest priority to allow
// reporting of the assertion failure and disable it from firing again.
NVIC_SetPriority((IRQn_Type)irqn, (1ul << __NVIC_PRIO_BITS) - 1ul);
Expand Down
4 changes: 2 additions & 2 deletions test/config/al-avreb-can.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<extends>modm:al-avreb-can</extends>
<options>
<option name="modm:build:build.path">../../build/generated-unittest/al-avreb-can/</option>
<option name="modm:build:scons:unittest.source">../../build/generated-unittest/al-avreb-can/modm-test</option>
<option name="modm:build:unittest.source">../../build/generated-unittest/al-avreb-can/modm-test</option>
<!-- <option name="modm:build:avrdude.programmer">avrispmkII</option> -->
<option name="modm:build:avrdude.programmer">usbasp-clone</option>
<option name="modm:build:scons:info.git">Disabled</option>
<option name="modm:build:info.git">Disabled</option>
<option name="modm:io:with_float">True</option>
<option name="modm:io:with_long_long">True</option>
<option name="modm:io:with_printf">True</option>
Expand Down
4 changes: 2 additions & 2 deletions test/config/arduino-nano_A.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<extends>modm:arduino-nano</extends>
<options>
<option name="modm:build:build.path">../../build/generated-unittest/arduino-nano_A/</option>
<option name="modm:build:scons:unittest.source">../../build/generated-unittest/arduino-nano_A/modm-test</option>
<option name="modm:build:scons:info.git">Disabled</option>
<option name="modm:build:unittest.source">../../build/generated-unittest/arduino-nano_A/modm-test</option>
<option name="modm:build:info.git">Disabled</option>
<option name="modm:io:with_float">True</option>
<option name="modm:io:with_long_long">True</option>
<option name="modm:io:with_printf">True</option>
Expand Down
4 changes: 2 additions & 2 deletions test/config/arduino-nano_B.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<extends>modm:arduino-nano</extends>
<options>
<option name="modm:build:build.path">../../build/generated-unittest/arduino-nano_B/</option>
<option name="modm:build:scons:unittest.source">../../build/generated-unittest/arduino-nano_B/modm-test</option>
<option name="modm:build:scons:info.git">Disabled</option>
<option name="modm:build:unittest.source">../../build/generated-unittest/arduino-nano_B/modm-test</option>
<option name="modm:build:info.git">Disabled</option>
<option name="modm:io:with_float">True</option>
<option name="modm:io:with_long_long">True</option>
<option name="modm:io:with_printf">True</option>
Expand Down
4 changes: 2 additions & 2 deletions test/config/arduino-nano_C.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<extends>modm:arduino-nano</extends>
<options>
<option name="modm:build:build.path">../../build/generated-unittest/arduino-nano_C/</option>
<option name="modm:build:scons:unittest.source">../../build/generated-unittest/arduino-nano_C/modm-test</option>
<option name="modm:build:scons:info.git">Disabled</option>
<option name="modm:build:unittest.source">../../build/generated-unittest/arduino-nano_C/modm-test</option>
<option name="modm:build:info.git">Disabled</option>
<option name="modm:io:with_float">True</option>
<option name="modm:io:with_long_long">True</option>
<option name="modm:io:with_printf">True</option>
Expand Down
4 changes: 2 additions & 2 deletions test/config/arduino-nano_D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<extends>modm:arduino-nano</extends>
<options>
<option name="modm:build:build.path">../../build/generated-unittest/arduino-nano_D/</option>
<option name="modm:build:scons:unittest.source">../../build/generated-unittest/arduino-nano_D/modm-test</option>
<option name="modm:build:scons:info.git">Disabled</option>
<option name="modm:build:unittest.source">../../build/generated-unittest/arduino-nano_D/modm-test</option>
<option name="modm:build:info.git">Disabled</option>
<option name="modm:io:with_float">True</option>
<option name="modm:io:with_long_long">True</option>
<option name="modm:io:with_printf">True</option>
Expand Down
Loading