Skip to content

Commit 9eccba3

Browse files
committed
SPI and SD card working but need DMA
Signed-off-by: Alexis Jeandet <[email protected]>
1 parent f44e6c7 commit 9eccba3

File tree

12 files changed

+979
-85
lines changed

12 files changed

+979
-85
lines changed

stm32/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ SET(CMAKE_OBJDUMP arm-none-eabi-objdump)
4747

4848
SET(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F746NGHX_FLASH.ld)
4949

50-
SET(OPTIM_LEVEL "-O0")
50+
SET(OPTIM_LEVEL "-O1")
5151
SET(CPP_STANDARD "gnu++17")
5252

5353
SET(CMAKE_CXX_FLAGS "${OPTIM_LEVEL} -mcpu=cortex-m7 -flto -std=${CPP_STANDARD} -g3 -DSTM32 -DSTM32F746NGHx -DSTM32F746G_DISCO -DSTM32F7 -DDEBUG -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti -fno-threadsafe-statics -fno-use-cxa-atexit -Wall -fstack-usage --specs=nano.specs -mfpu=fpv5-sp-d16 -mfloat-abi=hard")

stm32/Src/main.cpp

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#include "../../ucpp/register.hpp"
1717
#include "../../ucpp/sdcard/sdcard.hpp"
1818
#include "../../ucpp/spi.hpp"
19+
#include "../../ucpp/stm32/dma-regs.hpp"
1920
#include "../../ucpp/stm32/gpio.hpp"
21+
#include "../../ucpp/stm32/pwr-regs.hpp"
2022
#include "../../ucpp/stm32/rcc.hpp"
2123
#include "../../ucpp/stm32/sdmmc.hpp"
2224
#include "../../ucpp/stm32/spi.hpp"
@@ -33,6 +35,25 @@ using namespace ucpp::stm32;
3335
// SDMMC_D3 (PC11) AF12
3436
// SDMMC_CK (PC12) AF12
3537
// SDMMC_CMD (PD2) AF12
38+
void setup_clocks()
39+
{
40+
// using CR_t = decltype(stm32f7.rcc.CR);
41+
// using CFGR_t = decltype(stm32f7.rcc.CFGR);
42+
// stm32f7.rcc.CR |= 1;
43+
// stm32f7.rcc.CFGR = 0;
44+
// stm32f7.rcc.CR &= 0xFEF6FFFF;
45+
// stm32f7.rcc.PLLCFGR = 0x24003010;
46+
// stm32f7.rcc.CR &= 0xFFFBFFFF;
47+
// stm32f7.rcc.CIR = 0;
48+
// stm32f7.rcc.APB1ENR.PWREN = 1;
49+
// stm32f7.rcc.APB2ENR.SYSCFGEN = 1;
50+
// stm32f7.pwr.CR1.VOS = 1;
51+
// stm32f7.rcc.CR = CR_t::HSION.shift(1) | CR_t::HSITRIM.shift(2);
52+
// while (!stm32f7.rcc.CR.HSIRDY)
53+
// ;
54+
// stm32f7.rcc.CFGR = CFGR_t::SW0.shift(0) | CFGR_t::HPRE.shift(0) | CFGR_t::PPRE1.shift(0)
55+
// | CFGR_t::PPRE2.shift(0);
56+
}
3657

3758
template <typename gpio_t, gpio::alternate_function af, int I>
3859
inline void _setup_all_af(gpio_t& gpio)
@@ -106,6 +127,11 @@ inline void setup_codec_io()
106127
speed_field<8>(stm32f7.GPIOA) = gpio::speed::very_high;
107128
}
108129

130+
void test_timer12()
131+
{
132+
stm32f7.rcc.APB1ENR.TIM12EN = 1;
133+
*reinterpret_cast<volatile uint32_t*>(0x40001800) = 1;
134+
}
109135

110136
int main(void)
111137
{
@@ -117,31 +143,33 @@ int main(void)
117143
volatile gpio::gpio_c_t* gpioi = (gpio::gpio_c_t*)(stm32f7.GPIOI.address);
118144
volatile sdmmc::sdmmc_c_t* sdmmc1 = (sdmmc::sdmmc_c_t*)(stm32f7.sdmmc.address);
119145
volatile spi::spi_c_t* spi2 = (spi::spi_c_t*)(stm32f7.SPI2.address);
146+
volatile spi::spi_c_t* spi6 = (spi::spi_c_t*)(stm32f7.SPI6.address);
147+
volatile uint32_t* timer12_CR = reinterpret_cast<volatile uint32_t*>(0x40001800);
120148
// ===========================================================================
149+
setup_clocks();
150+
rcc::enable_clock(stm32f7.rcc, stm32f7.SPI2);
151+
rcc::enable_clock(stm32f7.rcc, stm32f7.SPI6);
121152
rcc::enable_clock(stm32f7.rcc, stm32f7.GPIOA);
122153
rcc::enable_clock(stm32f7.rcc, stm32f7.GPIOB);
123154
rcc::enable_clock(stm32f7.rcc, stm32f7.GPIOC);
124155
rcc::enable_clock(stm32f7.rcc, stm32f7.GPIOD);
125156
rcc::enable_clock(stm32f7.rcc, stm32f7.GPIOI);
126157
rcc::enable_clock(stm32f7.rcc, stm32f7.GPIOK);
127-
rcc::enable_clock(stm32f7.rcc, stm32f7.SPI2);
128-
stm32f7.rcc.APB1ENR.SPI2EN = 1;
129-
stm32f7.rcc.APB1RSTR.SPI2RST = 1;
130-
stm32f7.rcc.APB1RSTR.SPI2RST = 0;
131-
stm32f7.rcc.APB1ENR.SPI2EN = 1;
158+
rcc::enable_clock(stm32f7.rcc, stm32f7.sdmmc);
159+
// test_timer12();
132160
// GPIO K3 = LCD backlight ctrl
133-
gpio::mode_field<3>(stm32f7.GPIOK) = gpio::mode::output;
134-
stm32f7.GPIOK.output_typer.get<3>() = gpio::output_type::open_drain;
135-
stm32f7.GPIOK.speedr.get<3>() = gpio::speed::very_high;
161+
// gpio::mode_field<3>(stm32f7.GPIOK) = gpio::mode::output;
162+
// stm32f7.GPIOK.output_typer.get<3>() = gpio::output_type::open_drain;
163+
// stm32f7.GPIOK.speedr.get<3>() = gpio::speed::very_high;
136164
// sdcard_init();
137165
setup_sd_io();
138166
setup_codec_io();
139167
ucpp::sdcard::Sdcard<ucpp::stm32::sdmmc::sdmmc_ctrlr<decltype(stm32f7.sdmmc)>> sdcrad;
140168
sdcrad.init();
141169
using codec_t = ucpp::codec::vs1002<ucpp::stm32::spi::SPI<decltype(stm32f7.SPI2)>, vs1002_io>;
142-
stm32f7.SPI2.CR1 = (1 << 2) + (1 << 6);
170+
143171
codec_t::init();
144-
int block = 0;
172+
int block = 2;
145173
for (;;)
146174
{
147175
char data[1024];

stm32/Startup/startup_stm32f746nghx.s

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,16 @@ LoopFillZerobss:
7575
cmp r2, r4
7676
bcc FillZerobss
7777

78+
79+
LDR R0, =0xE000ED88
80+
LDR r1, [R0]
81+
ORR R1, R1, #(0xF << 20)
82+
STR R1, [R0]
83+
DSB
84+
ISB
85+
7886
/* Call the clock system intitialization function.*/
79-
bl SystemInit
87+
// bl SystemInit
8088
/* Call static constructors */
8189
bl __libc_init_array
8290
/* Call the application's entry point.*/

ucpp/peripherals_tags.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ DECLARE_DEVICE(uart)
2525
DECLARE_DEVICE(gpio)
2626
DECLARE_DEVICE(sdmmc)
2727
DECLARE_DEVICE(spi)
28-
28+
DECLARE_DEVICE(pwr)
29+
DECLARE_DEVICE(scb)
30+
DECLARE_DEVICE(dma)
2931
DECLARE_DEVICE(apb_bus)
3032

3133
}

ucpp/stm32/Rerister_generator.ipynb

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"execution_count": 1,
66
"metadata": {
77
"ExecuteTime": {
8-
"end_time": "2019-11-26T15:42:53.034342Z",
9-
"start_time": "2019-11-26T15:42:53.030762Z"
8+
"end_time": "2019-12-01T16:09:55.005916Z",
9+
"start_time": "2019-12-01T16:09:54.987309Z"
1010
}
1111
},
1212
"outputs": [],
@@ -20,8 +20,8 @@
2020
"execution_count": 2,
2121
"metadata": {
2222
"ExecuteTime": {
23-
"end_time": "2019-11-26T15:42:53.663334Z",
24-
"start_time": "2019-11-26T15:42:53.210469Z"
23+
"end_time": "2019-12-01T16:09:55.855811Z",
24+
"start_time": "2019-12-01T16:09:55.401103Z"
2525
}
2626
},
2727
"outputs": [],
@@ -35,8 +35,8 @@
3535
"execution_count": 3,
3636
"metadata": {
3737
"ExecuteTime": {
38-
"end_time": "2019-11-26T15:42:53.750616Z",
39-
"start_time": "2019-11-26T15:42:53.747051Z"
38+
"end_time": "2019-12-01T16:09:55.968736Z",
39+
"start_time": "2019-12-01T16:09:55.965192Z"
4040
}
4141
},
4242
"outputs": [],
@@ -66,8 +66,8 @@
6666
"execution_count": 4,
6767
"metadata": {
6868
"ExecuteTime": {
69-
"end_time": "2019-11-26T15:42:53.918127Z",
70-
"start_time": "2019-11-26T15:42:53.824822Z"
69+
"end_time": "2019-12-01T16:09:56.182167Z",
70+
"start_time": "2019-12-01T16:09:56.081892Z"
7171
}
7272
},
7373
"outputs": [],
@@ -205,8 +205,8 @@
205205
"execution_count": 5,
206206
"metadata": {
207207
"ExecuteTime": {
208-
"end_time": "2019-11-26T15:42:54.189724Z",
209-
"start_time": "2019-11-26T15:42:54.179353Z"
208+
"end_time": "2019-12-01T16:09:56.600236Z",
209+
"start_time": "2019-12-01T16:09:56.589026Z"
210210
}
211211
},
212212
"outputs": [
@@ -235,8 +235,8 @@
235235
"execution_count": 6,
236236
"metadata": {
237237
"ExecuteTime": {
238-
"end_time": "2019-11-26T15:42:54.463624Z",
239-
"start_time": "2019-11-26T15:42:54.460003Z"
238+
"end_time": "2019-12-01T16:09:57.046468Z",
239+
"start_time": "2019-12-01T16:09:57.041260Z"
240240
}
241241
},
242242
"outputs": [
@@ -257,11 +257,11 @@
257257
},
258258
{
259259
"cell_type": "code",
260-
"execution_count": 8,
260+
"execution_count": 7,
261261
"metadata": {
262262
"ExecuteTime": {
263-
"end_time": "2019-11-26T15:42:54.907993Z",
264-
"start_time": "2019-11-26T15:42:54.900512Z"
263+
"end_time": "2019-12-01T16:09:57.776282Z",
264+
"start_time": "2019-12-01T16:09:57.769338Z"
265265
}
266266
},
267267
"outputs": [],
@@ -294,19 +294,22 @@
294294
},
295295
{
296296
"cell_type": "code",
297-
"execution_count": 9,
297+
"execution_count": 10,
298298
"metadata": {
299299
"ExecuteTime": {
300-
"end_time": "2019-11-26T15:42:55.845949Z",
301-
"start_time": "2019-11-26T15:42:55.692805Z"
300+
"end_time": "2019-12-01T20:50:13.168018Z",
301+
"start_time": "2019-12-01T20:50:12.842327Z"
302302
}
303303
},
304304
"outputs": [],
305305
"source": [
306306
"make_header(d.peripherals[\"RCC\"], \"no_tag\")\n",
307307
"make_header(d.peripherals[\"GPIOA\"],\"gpio_tag\",\"gpio\")\n",
308308
"make_header(d.peripherals[\"SDMMC1\"],\"sdmmc_tag\", \"sdmmc\")\n",
309-
"make_header(d.peripherals[\"SPI1\"],\"spi_tag\", \"spi\")"
309+
"make_header(d.peripherals[\"SPI1\"],\"spi_tag\", \"spi\")\n",
310+
"make_header(d.peripherals[\"PWR\"],\"pwr_tag\", \"pwr\")\n",
311+
"make_header(d.peripherals[\"SCB\"],\"scb_tag\", \"scb\")\n",
312+
"make_header(d.peripherals[\"DMA1\"],\"dma_tag\", \"dma\")"
310313
]
311314
},
312315
{

0 commit comments

Comments
 (0)