Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

stm32h7: support setting bus frequency in SPI driver

Change-Id: I71edf28fdc24d8a00d27aa727815f99e788b675a

authored by

Aidan MacDonald and committed by
Solomon Peachy
5137ef49 a4b0af2a

+41 -1
+13
firmware/target/arm/stm32/echoplayer/clock-echoplayer.c
··· 162 162 break; 163 163 } 164 164 } 165 + 166 + size_t stm_target_clock_get_frequency(enum stm_clock clock) 167 + { 168 + switch (clock) 169 + { 170 + case STM_CLOCK_SPI5_KER: 171 + return STM32_HSE_FREQ; 172 + 173 + default: 174 + panicf("%s: unsupported clock %d", __func__, (int)clock); 175 + return 0; 176 + } 177 + }
+4
firmware/target/arm/stm32/echoplayer/lcd-echoplayer.c
··· 28 28 #include "regs/stm32h743/rcc.h" 29 29 #include "regs/stm32h743/spi.h" 30 30 31 + /* ILI9342C specifies 10 MHz max */ 32 + #define LCD_SPI_FREQ 10000000 33 + 31 34 struct stm_spi_config spi_cfg = { 32 35 .instance = ITA_SPI5, 33 36 .clock = STM_CLOCK_SPI5_KER, 37 + .freq = LCD_SPI_FREQ, 34 38 .mode = STM_SPIMODE_HALF_DUPLEX, 35 39 .proto = STM_SPIPROTO_MOTOROLA, 36 40 .frame_bits = 9,
+14 -1
firmware/target/arm/stm32/spi-stm32h7.c
··· 108 108 *sizep = 0; 109 109 } 110 110 111 + static uint32_t stm_spi_calc_mbr(const struct stm_spi_config *config) 112 + { 113 + size_t ker_freq = stm_clock_get_frequency(config->clock); 114 + for (uint32_t mbr = 0; mbr <= 7; mbr++) 115 + { 116 + if (ker_freq / (2 << mbr) <= config->freq) 117 + return mbr; 118 + } 119 + 120 + panicf("%s: impossible frequency", __func__); 121 + } 122 + 111 123 void stm_spi_init(struct stm_spi *spi, 112 124 const struct stm_spi_config *config) 113 125 { 114 126 uint32_t ftlevel; 127 + uint32_t mbr = stm_spi_calc_mbr(config); 115 128 116 129 spi->regs = config->instance; 117 130 spi->clock = config->clock; ··· 153 166 154 167 /* TODO: allow setting MBR here */ 155 168 reg_writelf(spi->regs, SPI_CFG1, 156 - MBR(0), 169 + MBR(mbr), 157 170 CRCEN(0), 158 171 CRCSIZE(7), 159 172 TXDMAEN(0),
+10
firmware/target/arm/stm32/spi-stm32h7.h
··· 50 50 { 51 51 /* Peripheral instance base address; one of ITA_SPIx */ 52 52 uint32_t instance; 53 + 54 + /* 55 + * SPI kernel clock and requested SPI bus frequency. 56 + * The frequency is used to set the SPI master baud 57 + * rate setting based on the kernel clock input, as 58 + * such the kernel clock should not be changed after 59 + * the SPI peripheral is initialized. 60 + */ 53 61 enum stm_clock clock; 62 + size_t freq; 63 + 54 64 enum stm_spi_mode mode; 55 65 enum stm_spi_protocol proto; 56 66 stm_spi_set_cs_t set_cs;