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

Nucleo-L452RE BSP & 2046 Touch driver & minor fixes #600

Merged
merged 7 commits into from
Apr 1, 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
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
- name: Examples STM32L4 Series
if: always()
run: |
(cd examples && ../tools/scripts/examples_compile.py stm32l476_discovery nucleo_l476rg nucleo_l432kc)
(cd examples && ../tools/scripts/examples_compile.py stm32l476_discovery nucleo_l476rg nucleo_l432kc nucleo_l452re)
- name: Examples STM32G4 Series
if: always()
run: |
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,15 @@ We have out-of-box support for many development boards including documentation.
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l152re">NUCLEO-L152RE</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l432kc">NUCLEO-L432KC</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l452re">NUCLEO-L452RE</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l476rg">NUCLEO-L476RG</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-olimexino-stm32">OLIMEXINO-STM32</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-raspberrypi">Raspberry Pi</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-board-raspberrypi">Raspberry Pi</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-samd21-mini">SAMD21-MINI</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-stm32_f4ve">STM32-F4VE</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-board-stm32f030_demo">STM32F030-DEMO</a></td>
</tr><tr>
</tr>
</table>
<!--/bsptable-->
Expand Down Expand Up @@ -573,6 +575,7 @@ you specific needs.
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp102">TMP102</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp175">TMP175</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-touch2046">TOUCH2046</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl53l0">VL53L0</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl6180">VL6180</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ws2812">WS2812</a></td>
Expand Down
1 change: 1 addition & 0 deletions examples/blue_pill_f103/graphics/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ main()
display::Sck::Sck, display::Miso::Miso, display::Mosi::Mosi>();
display::Spi::initialize<SystemClock, 1125_kHz>();
tft.initialize();
tft.enableBacklight(true);
LedGreen::set();
tft.setColor(modm::glcd::Color::black());
int16_t w = tft.getWidth();
Expand Down
27 changes: 27 additions & 0 deletions examples/nucleo_l452re/blink/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2021, Raphael Lehmann
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <modm/board.hpp>

using namespace Board;

int
main()
{
initialize();

while (true)
{
LedGreen::toggle();
modm::delay(Button::read() ? 250ms : 500ms);
}

return 0;
}
10 changes: 10 additions & 0 deletions examples/nucleo_l452re/blink/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:nucleo-l452re</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_l452r3/blink</option>
</options>
<modules>
<module>modm:platform:gpio</module>
<module>modm:build:scons</module>
</modules>
</library>
140 changes: 140 additions & 0 deletions examples/nucleo_l452re/graphics_touch/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* Copyright (c) 2021, Henrik Hose
* Copyright (c) 2021, Raphael Lehmann
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <modm/board.hpp>
#include <modm/driver/display/ili9341_spi.hpp>

#include <modm/driver/touch/touch2046.hpp>

using namespace Board;

namespace tft
{
using DmaRx = Dma1::Channel2;
using DmaTx = Dma1::Channel3;
using Spi = SpiMaster1_Dma<DmaRx, DmaTx>;
//using Spi = SpiMaster1;
using Cs = modm::platform::GpioC8;
using Sck = modm::platform::GpioA5;
using Miso = modm::platform::GpioA6;
using Mosi = modm::platform::GpioA7;
using DataCommands = modm::platform::GpioC5;
using Reset = modm::platform::GpioC6;
using Backlight = modm::platform::GpioC9;
}

modm::Ili9341Spi<
tft::Spi,
tft::Cs,
tft::DataCommands,
tft::Reset,
tft::Backlight
> tftController;

namespace touch
{
using Spi = SpiMaster2;
using Cs = modm::platform::GpioB3;
using Sck = modm::platform::GpioB13;
using Miso = modm::platform::GpioB14;
using Mosi = modm::platform::GpioB15;
//using Interrupt = modm::platform::GpioA10;
}

modm::Touch2046<touch::Spi, touch::Cs> touchController;


int
main()
{
using namespace modm::literals;
Board::initialize();
Dma1::enable();

tft::Spi::connect<
tft::Sck::Sck,
tft::Miso::Miso,
tft::Mosi::Mosi>();
tft::Spi::initialize<SystemClock, 40_MHz>();
tftController.initialize();
tftController.enableBacklight(true);

touch::Spi::connect<
touch::Sck::Sck,
touch::Miso::Miso,
touch::Mosi::Mosi>();
touch::Spi::initialize<SystemClock, 2500_kHz>();
modm::touch2046::Calibration cal{
.OffsetX = -11,
.OffsetY = 335,
.FactorX = 22018,
.FactorY = -29358,
.MaxX = 240,
.MaxY = 320,
.ThresholdZ = 500,
};
touchController.setCalibration(cal);

LedGreen::set();

tftController.setColor(modm::glcd::Color::black());
tftController.setBackgroundColor(modm::glcd::Color::red());
tftController.clear();

tftController.setFont(modm::font::ArcadeClassic);
tftController.setColor(modm::glcd::Color::white());
tftController.setCursor(10,12);
tftController << "(10,10)";
tftController.setCursor(150,202);
tftController << "(150,200)";
tftController.drawLine(5, 10, 15, 10);
tftController.drawLine(10, 5, 10, 15);
tftController.drawLine(145, 200, 155, 200);
tftController.drawLine(150, 195, 150, 205);

tftController.setColor(modm::glcd::Color::black());
tftController.setFont(modm::font::Ubuntu_36);

int16_t X = 0;
int16_t Y = 0;
int16_t Z = 0;

while (true)
{
LedGreen::set();

std::tie(X, Y, Z) = RF_CALL_BLOCKING(touchController.getRawValues());
tftController.setColor(modm::glcd::Color::red());
tftController.fillRectangle({30, 50}, 90, 115);
tftController.setColor(modm::glcd::Color::black());
tftController.setCursor(0, 50);
tftController << "X=" << X;
tftController.setCursor(0, 90);
tftController << "Y=" << Y;
tftController.setCursor(0, 130);
tftController << "Z=" << Z;

tftController.setColor(modm::glcd::Color::red());
tftController.fillRectangle({30, 220}, 120, 35);
tftController.setColor(modm::glcd::Color::black());
if(RF_CALL_BLOCKING(touchController.isTouched())) {
std::tie(X, Y) = RF_CALL_BLOCKING(touchController.getTouchPosition());
tftController.setCursor(5, 220);
tftController << "> (" << X << "," << Y << ")";
}

LedGreen::reset();
modm::delay(300ms);
}

return 0;
}
15 changes: 15 additions & 0 deletions examples/nucleo_l452re/graphics_touch/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<library>
<extends>modm:nucleo-l452re</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_l452re/graphics_touch</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:driver:ili9341</module>
<module>modm:driver:touch2046</module>
<module>modm:platform:spi:1</module>
<module>modm:platform:spi:2</module>
<module>modm:platform:dma</module>
<module>modm:docs</module>
</modules>
</library>
4 changes: 2 additions & 2 deletions src/modm/architecture/interface/spi_master.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class SpiMaster : public ::modm::PeripheralDriver, public Spi
* number of bytes to be shifted out
*/
static void
transferBlocking(uint8_t *tx, uint8_t *rx, std::size_t length);
transferBlocking(const uint8_t *tx, uint8_t *rx, std::size_t length);

/**
* Swap a single byte and wait for completion non-blocking!.
Expand Down Expand Up @@ -154,7 +154,7 @@ class SpiMaster : public ::modm::PeripheralDriver, public Spi
* number of bytes to be shifted out
*/
static modm::ResumableResult<void>
transfer(uint8_t *tx, uint8_t *rx, std::size_t length);
transfer(const uint8_t *tx, uint8_t *rx, std::size_t length);
#endif
};

Expand Down
137 changes: 137 additions & 0 deletions src/modm/board/nucleo_l452re/board.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// coding: utf-8
/*
* Copyright (c) 2017, Sascha Schade
* Copyright (c) 2017-2018, Niklas Hauser
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#ifndef MODM_STM32_NUCLEO_L452RE_HPP
#define MODM_STM32_NUCLEO_L452RE_HPP

#include <modm/platform.hpp>
#include <modm/architecture/interface/clock.hpp>
#include <modm/debug/logger.hpp>
/// @ingroup modm_board_nucleo_l452re
#define MODM_BOARD_HAS_LOGGER

using namespace modm::platform;

/// @ingroup modm_board_nucleo_l452re
namespace Board
{
using namespace modm::literals;

/// STM32L4 running at 80MHz generated from the
/// internal high speed oscillator

// Dummy clock for devices
struct SystemClock {
static constexpr uint32_t Frequency = 80_MHz;
static constexpr uint32_t Ahb = Frequency;
static constexpr uint32_t Ahb2 = Frequency;
static constexpr uint32_t Apb1 = Frequency;
static constexpr uint32_t Apb2 = Frequency;

static constexpr uint32_t Adc1 = Ahb2;

static constexpr uint32_t Can1 = Apb1;

static constexpr uint32_t Comp1 = Apb2;
static constexpr uint32_t Comp2 = Apb2;

static constexpr uint32_t Dac1 = Apb1;

static constexpr uint32_t I2c1 = Apb1;
static constexpr uint32_t I2c2 = Apb1;
static constexpr uint32_t I2c3 = Apb1;
static constexpr uint32_t I2c4 = Apb1;

static constexpr uint32_t Spi1 = Apb2;

static constexpr uint32_t Spi2 = Apb1;
static constexpr uint32_t Spi3 = Apb1;

static constexpr uint32_t Timer1 = Apb2;

static constexpr uint32_t Timer2 = Apb1;
static constexpr uint32_t Timer6 = Apb1;

static constexpr uint32_t Timer15 = Apb2;
static constexpr uint32_t Timer16 = Apb2;

static constexpr uint32_t Uart4 = Apb1;

static constexpr uint32_t Usart1 = Apb2;

static constexpr uint32_t Usart2 = Apb1;
static constexpr uint32_t Usart3 = Apb1;

static constexpr uint32_t Usb = Apb1;

static bool inline
enable()
{
Rcc::enableInternalClock(); // 16MHz
Rcc::PllFactors pllFactors{
.pllM = 1, // 16MHz / M= 1 -> 16MHz
.pllN = 10, // 16MHz * N=10 -> 160MHz
.pllR = 2, // 160MHz / R= 2 -> 80MHz = F_cpu
};
Rcc::enablePll(Rcc::PllSource::InternalClock, pllFactors);
Rcc::setFlashLatency<Frequency>();
// switch system clock to PLL output
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
// APB1 has max. 80MHz
Rcc::setApb1Prescaler(Rcc::Apb1Prescaler::Div1);
Rcc::setApb2Prescaler(Rcc::Apb2Prescaler::Div1);
// update frequencies for busy-wait delay functions
Rcc::updateCoreFrequency<Frequency>();

return true;
}
};

// Arduino Footprint
#include "nucleo64_arduino.hpp"

// Button connects to GND
using Button = GpioInverted<GpioInputC13>;

// User LD2
using LedGreen = GpioOutputA5;
using Leds = SoftwareGpioPort< LedGreen >;

namespace stlink
{
using Tx = GpioOutputA2;
using Rx = GpioInputA3;
using Uart = Usart2;
}

using LoggerDevice = modm::IODeviceWrapper< stlink::Uart, modm::IOBuffer::BlockIfFull >;


inline void
initialize()
{
SystemClock::enable();
SysTickTimer::initialize<SystemClock>();

stlink::Uart::connect<stlink::Tx::Tx, stlink::Rx::Rx>();
stlink::Uart::initialize<SystemClock, 115200_Bd>();

LedGreen::setOutput(modm::Gpio::Low);

Button::setInput();
}

} // Board namespace

#endif // MODM_STM32_NUCLEO_L452RE_HPP
Loading