Skip to content
Snippets Groups Projects
Commit 1884c479 authored by Per Lindgren's avatar Per Lindgren
Browse files

memory.x and Cargo.toml updates

parent e0f3adf8
No related branches found
No related tags found
No related merge requests found
# Changelog # Changelog
## 2021-02-22
- memory.x, reduced flash size to 128k to match light-weight target
- Cargo.toml, updated dependencies to latest stm32f4xx-hal/pac
Some experiments (wip):
- examples/rtt_rtic_i2c.rs, spi emulation over i2c
- src/pwm3389e, driver using emulated spi
## 2021-02-16 ## 2021-02-16
- rtt_rtic_usb_mouse updated - rtt_rtic_usb_mouse updated
......
...@@ -6,7 +6,7 @@ name = "app" ...@@ -6,7 +6,7 @@ name = "app"
version = "0.1.0" version = "0.1.0"
[dependencies] [dependencies]
cortex-m = "0.6.4" cortex-m = "0.7.1"
cortex-m-rt = "0.6.13" cortex-m-rt = "0.6.13"
cortex-m-semihosting = "0.3.7" cortex-m-semihosting = "0.3.7"
cortex-m-rtic = "0.5.5" cortex-m-rtic = "0.5.5"
...@@ -17,19 +17,19 @@ usb-device = "0.2.7" ...@@ -17,19 +17,19 @@ usb-device = "0.2.7"
panic-halt = "0.2.0" panic-halt = "0.2.0"
# Uncomment for the itm panic examples. # Uncomment for the itm panic examples.
panic-itm = "0.4.2" #panic-itm = "0.4.2"
# Uncomment for the rtt-timing examples. # Uncomment for the rtt-timing examples.
panic-rtt-target = { version = "0.1.1", features = ["cortex-m"] } panic-rtt-target = { version = "0.1.1", features = ["cortex-m"] }
# Uncomment for the semihosting examples. # Uncomment for the semihosting examples.
panic-semihosting = "0.5.6" #panic-semihosting = "0.5.6"
# Tracing # Tracing
rtt-target = { version = "0.3.0", features = ["cortex-m"] } rtt-target = { version = "0.3.0", features = ["cortex-m"] }
[dependencies.stm32f4] [dependencies.stm32f4]
version = "0.12.1" version = "0.13.0"
features = ["stm32f411", "rt"] features = ["stm32f411", "rt"]
# Uncomment for the allocator example. # Uncomment for the allocator example.
...@@ -71,7 +71,3 @@ lto = true # better optimizations ...@@ -71,7 +71,3 @@ lto = true # better optimizations
# test = false # test = false
# bench = false # bench = false
# [profile.release]
# codegen-units = 1 # better optimizations
# debug = true # symbols are nice and they don't increase the size on Flash
# lto = true # better optimizations
...@@ -85,8 +85,12 @@ Using `vscode` just press F5 to launch and debug the program in the currently ac ...@@ -85,8 +85,12 @@ Using `vscode` just press F5 to launch and debug the program in the currently ac
## Nucleo Connections ## Nucleo Connections
---
Some of the examples need external connection to the Nucleo to work. Some of the examples need external connection to the Nucleo to work.
---
### USB example ### USB example
| Signal | Color | Pin | Nucleo | | Signal | Color | Pin | Nucleo |
...@@ -98,6 +102,8 @@ Some of the examples need external connection to the Nucleo to work. ...@@ -98,6 +102,8 @@ Some of the examples need external connection to the Nucleo to work.
D+ used for re-enumeration. You don't need to connect the V+ from the USB cable, as the NUCLEO is self powered. D+ used for re-enumeration. You don't need to connect the V+ from the USB cable, as the NUCLEO is self powered.
---
### PWM example ### PWM example
| Signal | Pin | Nucleo | | Signal | Pin | Nucleo |
...@@ -105,6 +111,17 @@ D+ used for re-enumeration. You don't need to connect the V+ from the USB cable, ...@@ -105,6 +111,17 @@ D+ used for re-enumeration. You don't need to connect the V+ from the USB cable,
| PWM1 | PA8 | CN9 - 8 | | PWM1 | PA8 | CN9 - 8 |
| PWM2 | PA9 | CN5 - 1 | | PWM2 | PA9 | CN5 - 1 |
---
### I2C example
| Signal | Pin | Nucleo |
| -------- | --- | ------ |
| I2C1_SDA | PB9 | CN10-5 |
| I2C1_SCL | PB8 | CN10-3 |
| +3.3v | | CN7-16 |
| GND | | Gnd |
## Debug interface ## Debug interface
- Serial Wire debugging uses pins PA13 and PA14. So refrain from using those unless absolutely necessary. - Serial Wire debugging uses pins PA13 and PA14. So refrain from using those unless absolutely necessary.
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
#![no_std] #![no_std]
use cortex_m::{asm::delay, delay}; use cortex_m::{asm::delay, delay};
use panic_halt as _; // use panic_halt as _;
use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print}; use rtt_target::{rprintln, rtt_init_print};
use stm32f4xx_hal::{ use stm32f4xx_hal::{
...@@ -20,6 +21,11 @@ use stm32f4xx_hal::{ ...@@ -20,6 +21,11 @@ use stm32f4xx_hal::{
stm32::I2C1, stm32::I2C1,
}; };
use app::{
pmw3389e::{self, Register},
DwtDelay,
};
#[rtic::app(device = stm32f4xx_hal::stm32, peripherals = true)] #[rtic::app(device = stm32f4xx_hal::stm32, peripherals = true)]
const APP: () = { const APP: () = {
#[init] #[init]
...@@ -27,18 +33,14 @@ const APP: () = { ...@@ -27,18 +33,14 @@ const APP: () = {
rtt_init_print!(); rtt_init_print!();
rprintln!("init"); rprintln!("init");
let dp = cx.device; let dp = cx.device;
let mut cp = cx.core;
// Set up the system clock, 48MHz // Set up the system clock
let rcc = dp.RCC.constrain(); let rcc = dp.RCC.constrain();
// let clocks = rcc.cfgr.sysclk(48.mhz()).freeze();
let clocks = rcc.cfgr.freeze(); let clocks = rcc.cfgr.freeze();
// let clocks = rcc
// .cfgr // Initialize (enable) the monotonic timer (CYCCNT)
// .hclk(48.mhz()) cp.DCB.enable_trace();
// .sysclk(48.mhz())
// .pclk1(24.mhz())
// .pclk2(24.mhz())
// .freeze();
// Set up I2C. // Set up I2C.
let gpiob = dp.GPIOB.split(); let gpiob = dp.GPIOB.split();
...@@ -49,7 +51,7 @@ const APP: () = { ...@@ -49,7 +51,7 @@ const APP: () = {
rprintln!("i2c configured"); rprintln!("i2c configured");
use embedded_hal::spi::MODE_3; use embedded_hal::spi::MODE_3;
use SC18IS602::{Function, Order, Speed, SH18IS602}; use SC18IS602::{Order, Speed, SH18IS602};
let mut spi_emu = let mut spi_emu =
SH18IS602::new(i2c, 0, Order::MsbFirst, MODE_3, Speed::Speed1843kHz, true); SH18IS602::new(i2c, 0, Order::MsbFirst, MODE_3, Speed::Speed1843kHz, true);
...@@ -66,7 +68,7 @@ const APP: () = { ...@@ -66,7 +68,7 @@ const APP: () = {
// try split transaction // try split transaction
rprintln!("try split transaction"); rprintln!("try split transaction");
// the write part // the write part
spi_emu.set_low().ok(); spi_emu.set_low().unwrap();
let mut req = [0x00]; let mut req = [0x00];
spi_emu.transfer(&mut req).unwrap(); spi_emu.transfer(&mut req).unwrap();
rprintln!("id request {:02x?}", req); rprintln!("id request {:02x?}", req);
...@@ -77,11 +79,11 @@ const APP: () = { ...@@ -77,11 +79,11 @@ const APP: () = {
spi_emu.transfer(&mut req).unwrap(); spi_emu.transfer(&mut req).unwrap();
rprintln!("id resp {:02x?}", req); rprintln!("id resp {:02x?}", req);
spi_emu.set_high().ok(); spi_emu.set_high().unwrap();
rprintln!("try split transaction"); rprintln!("try split transaction");
// the write part // the write part
spi_emu.set_low().ok(); spi_emu.set_low().unwrap();
let mut req = [0x01]; let mut req = [0x01];
spi_emu.transfer(&mut req).unwrap(); spi_emu.transfer(&mut req).unwrap();
rprintln!("version request {:02x?}", req); rprintln!("version request {:02x?}", req);
...@@ -92,7 +94,12 @@ const APP: () = { ...@@ -92,7 +94,12 @@ const APP: () = {
spi_emu.transfer(&mut req).unwrap(); spi_emu.transfer(&mut req).unwrap();
rprintln!("version resp {:02x?}", req); rprintln!("version resp {:02x?}", req);
spi_emu.set_high().ok(); spi_emu.set_high().unwrap();
let delay = DwtDelay::new(&mut cp.DWT, clocks);
let pmw3389 = pmw3389e::Pmw3389e::new(spi_emu, delay).unwrap();
rprintln!("success");
} }
#[idle] #[idle]
...@@ -251,6 +258,8 @@ mod SC18IS602 { ...@@ -251,6 +258,8 @@ mod SC18IS602 {
} }
} }
// impl<I2C> Default for SH18IS602<I2C> where I2C: i2c::Write + i2c::Read {}
impl<I2C> Transfer<u8> for SH18IS602<I2C> impl<I2C> Transfer<u8> for SH18IS602<I2C>
where where
I2C: i2c::Write + i2c::Read, I2C: i2c::Write + i2c::Read,
...@@ -272,18 +281,20 @@ mod SC18IS602 { ...@@ -272,18 +281,20 @@ mod SC18IS602 {
// perform the transaction on words.len() + 1 bytes // perform the transaction on words.len() + 1 bytes
// the actual SPI transfer should be words.len() // the actual SPI transfer should be words.len()
rprintln!("transfer_write {:02x?}", &self.buff[0..words.len() + 1]); // rprintln!("transfer_write {:02x?}", &self.buff[0..words.len() + 1]);
self.i2c self.i2c
.write(self.addr, &self.buff[0..words.len() + 1]) .write(self.addr, &self.buff[0..words.len() + 1])
.map_err(|_| panic!()) .map_err(|_| panic!())
.ok(); .ok();
cortex_m::asm::delay(100_000);
// A short delay is needed
// For improved performance use write if result is not needed
cortex_m::asm::delay(1000);
self.i2c.read(self.addr, words).map_err(|_| panic!()).ok(); self.i2c.read(self.addr, words).map_err(|_| panic!()).ok();
cortex_m::asm::delay(100_000);
rprintln!("transfer_read {:02x?}", words); // rprintln!("transfer_read {:02x?}", words);
Ok(words) Ok(words)
} }
...@@ -304,6 +315,7 @@ mod SC18IS602 { ...@@ -304,6 +315,7 @@ mod SC18IS602 {
.write(self.addr, &[Function::GpioWrite.id(), 0x0]) .write(self.addr, &[Function::GpioWrite.id(), 0x0])
.map_err(|_| panic!()) .map_err(|_| panic!())
.ok(); .ok();
cortex_m::asm::delay(100_000);
Ok(()) Ok(())
} }
} }
......
...@@ -3,7 +3,7 @@ MEMORY ...@@ -3,7 +3,7 @@ MEMORY
/* NOTE 1 K = 1 KiBi = 1024 bytes */ /* NOTE 1 K = 1 KiBi = 1024 bytes */
/* TODO Adjust these memory regions to match your device memory layout */ /* TODO Adjust these memory regions to match your device memory layout */
/* These values correspond to the STM32F411 */ /* These values correspond to the STM32F411 */
FLASH : ORIGIN = 0x08000000, LENGTH = 256K FLASH : ORIGIN = 0x08000000, LENGTH = 128K
RAM : ORIGIN = 0x20000000, LENGTH = 64K RAM : ORIGIN = 0x20000000, LENGTH = 64K
} }
......
#![no_std] #![no_std]
pub mod pmw3389; pub mod pmw3389;
pub mod pmw3389e;
use stm32f4xx_hal::{prelude::*, rcc::Clocks, stm32}; use stm32f4xx_hal::{prelude::*, rcc::Clocks, stm32};
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment