enable all periph clocks by default on startup, added testing synchronous uart write command
This commit is contained in:
+11
-5
@@ -2,6 +2,7 @@
|
|||||||
// Created by MightyPork on 2017/11/26.
|
// Created by MightyPork on 2017/11/26.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <stm32f072xb.h>
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "usbd_core.h"
|
#include "usbd_core.h"
|
||||||
#include "USB/usb_device.h"
|
#include "USB/usb_device.h"
|
||||||
@@ -20,11 +21,16 @@ void plat_init_resources(void)
|
|||||||
{
|
{
|
||||||
uint32_t rv = 0;
|
uint32_t rv = 0;
|
||||||
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
// switch everything ON (we should not write reserved bits, but nothing bad seems to happen)
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
RCC->APB1ENR = 0xFFFFFFFF;
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
RCC->APB2ENR = 0xFFFFFFFF;
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
RCC->AHBENR = 0xFFFFFFFF; // GPIOs are here
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
||||||
|
// __HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
// __HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
|
// __HAL_RCC_GPIOC_CLK_ENABLE();
|
||||||
|
// __HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
// __HAL_RCC_GPIOE_CLK_ENABLE();
|
||||||
|
|
||||||
// --- Common unit drivers ---
|
// --- Common unit drivers ---
|
||||||
|
|
||||||
|
|||||||
@@ -239,12 +239,6 @@ static error_t UI2C_init(Unit *unit)
|
|||||||
configure_gpio_alternate(portname, pin_sda, af_i2c);
|
configure_gpio_alternate(portname, pin_sda, af_i2c);
|
||||||
configure_gpio_alternate(portname, pin_scl, af_i2c);
|
configure_gpio_alternate(portname, pin_scl, af_i2c);
|
||||||
|
|
||||||
if (priv->periph_num == 1) {
|
|
||||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
|
||||||
} else {
|
|
||||||
__HAL_RCC_I2C2_CLK_ENABLE();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Disable the selected I2Cx Peripheral */
|
/* Disable the selected I2Cx Peripheral */
|
||||||
LL_I2C_Disable(priv->periph);
|
LL_I2C_Disable(priv->periph);
|
||||||
LL_I2C_ConfigFilters(priv->periph,
|
LL_I2C_ConfigFilters(priv->periph,
|
||||||
@@ -269,14 +263,7 @@ static void UI2C_deInit(Unit *unit)
|
|||||||
// de-init the pins & peripheral only if inited correctly
|
// de-init the pins & peripheral only if inited correctly
|
||||||
if (unit->status == E_SUCCESS) {
|
if (unit->status == E_SUCCESS) {
|
||||||
assert_param(priv->periph);
|
assert_param(priv->periph);
|
||||||
|
|
||||||
LL_I2C_DeInit(priv->periph);
|
LL_I2C_DeInit(priv->periph);
|
||||||
|
|
||||||
if (priv->periph_num == 1) {
|
|
||||||
__HAL_RCC_I2C1_CLK_DISABLE();
|
|
||||||
} else {
|
|
||||||
__HAL_RCC_I2C2_CLK_DISABLE();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release all resources
|
// Release all resources
|
||||||
|
|||||||
@@ -296,12 +296,6 @@ static error_t USPI_init(Unit *unit)
|
|||||||
configure_gpio_alternate(spi_portname, pin_miso, af_spi);
|
configure_gpio_alternate(spi_portname, pin_miso, af_spi);
|
||||||
configure_gpio_alternate(spi_portname, pin_sck, af_spi);
|
configure_gpio_alternate(spi_portname, pin_sck, af_spi);
|
||||||
|
|
||||||
if (priv->periph_num == 1) {
|
|
||||||
__HAL_RCC_SPI1_CLK_ENABLE();
|
|
||||||
} else {
|
|
||||||
__HAL_RCC_SPI2_CLK_ENABLE();
|
|
||||||
}
|
|
||||||
|
|
||||||
// configure SSN GPIOs
|
// configure SSN GPIOs
|
||||||
{
|
{
|
||||||
// Claim all needed pins
|
// Claim all needed pins
|
||||||
@@ -346,14 +340,7 @@ static void USPI_deInit(Unit *unit)
|
|||||||
// de-init the pins & peripheral only if inited correctly
|
// de-init the pins & peripheral only if inited correctly
|
||||||
if (unit->status == E_SUCCESS) {
|
if (unit->status == E_SUCCESS) {
|
||||||
assert_param(priv->periph);
|
assert_param(priv->periph);
|
||||||
|
|
||||||
LL_SPI_DeInit(priv->periph);
|
LL_SPI_DeInit(priv->periph);
|
||||||
|
|
||||||
if (priv->periph_num == 1) {
|
|
||||||
__HAL_RCC_SPI1_CLK_DISABLE();
|
|
||||||
} else {
|
|
||||||
__HAL_RCC_SPI2_CLK_DISABLE();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release all resources
|
// Release all resources
|
||||||
|
|||||||
+40
-23
@@ -2,6 +2,7 @@
|
|||||||
// Created by MightyPork on 2018/01/02.
|
// Created by MightyPork on 2018/01/02.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <stm32f072xb.h>
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "comm/messages.h"
|
#include "comm/messages.h"
|
||||||
#include "unit_base.h"
|
#include "unit_base.h"
|
||||||
@@ -483,21 +484,11 @@ static error_t UUSART_init(Unit *unit)
|
|||||||
configure_gpio_alternate( mappings[5].port, mappings[5].pin, mappings[5].af);
|
configure_gpio_alternate( mappings[5].port, mappings[5].pin, mappings[5].af);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv->periph_num == 1) {
|
|
||||||
__HAL_RCC_USART1_CLK_ENABLE();
|
|
||||||
} else if (priv->periph_num == 2) {
|
|
||||||
__HAL_RCC_USART2_CLK_ENABLE();
|
|
||||||
} else if (priv->periph_num == 3) {
|
|
||||||
__HAL_RCC_USART3_CLK_ENABLE();
|
|
||||||
} else if (priv->periph_num == 4) {
|
|
||||||
__HAL_RCC_USART4_CLK_ENABLE();
|
|
||||||
}
|
|
||||||
|
|
||||||
LL_USART_Disable(priv->periph);
|
LL_USART_Disable(priv->periph);
|
||||||
{
|
{
|
||||||
LL_USART_DeInit(priv->periph);
|
LL_USART_DeInit(priv->periph);
|
||||||
LL_USART_SetBaudRate(priv->periph,
|
LL_USART_SetBaudRate(priv->periph,
|
||||||
PLAT_AHB_MHZ/2,//FIXME this isn't great ...
|
PLAT_AHB_MHZ*1000000,//FIXME this isn't great ...
|
||||||
LL_USART_OVERSAMPLING_16,
|
LL_USART_OVERSAMPLING_16,
|
||||||
priv->baudrate);
|
priv->baudrate);
|
||||||
|
|
||||||
@@ -579,18 +570,7 @@ static void UUSART_deInit(Unit *unit)
|
|||||||
// de-init the pins & peripheral only if inited correctly
|
// de-init the pins & peripheral only if inited correctly
|
||||||
if (unit->status == E_SUCCESS) {
|
if (unit->status == E_SUCCESS) {
|
||||||
assert_param(priv->periph);
|
assert_param(priv->periph);
|
||||||
|
|
||||||
LL_USART_DeInit(priv->periph);
|
LL_USART_DeInit(priv->periph);
|
||||||
|
|
||||||
if (priv->periph_num == 1) {
|
|
||||||
__HAL_RCC_USART1_CLK_DISABLE();
|
|
||||||
} else if (priv->periph_num == 2) {
|
|
||||||
__HAL_RCC_USART2_CLK_DISABLE();
|
|
||||||
} else if (priv->periph_num == 3) {
|
|
||||||
__HAL_RCC_USART3_CLK_DISABLE();
|
|
||||||
} else if (priv->periph_num == 4) {
|
|
||||||
__HAL_RCC_USART4_CLK_DISABLE();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release all resources
|
// Release all resources
|
||||||
@@ -603,6 +583,30 @@ static void UUSART_deInit(Unit *unit)
|
|||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static error_t usart_wait_until_flag(struct priv *priv, uint32_t flag, bool stop_state)
|
||||||
|
{
|
||||||
|
uint32_t t_start = HAL_GetTick();
|
||||||
|
while (((priv->periph->ISR & flag) != 0) != stop_state) {
|
||||||
|
if (HAL_GetTick() - t_start > 10) {
|
||||||
|
dbg("ERR waiting for ISR flag 0x%p = %d", (void*)flag, (int)stop_state);
|
||||||
|
return E_HW_TIMEOUT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return E_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static error_t sync_send(struct priv *priv, const uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
|
while (len > 0) {
|
||||||
|
TRY(usart_wait_until_flag(priv, USART_ISR_TXE, 1));
|
||||||
|
priv->periph->TDR = *buf++;
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
TRY(usart_wait_until_flag(priv, USART_ISR_TC, 1));
|
||||||
|
return E_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
enum PinCmd_ {
|
enum PinCmd_ {
|
||||||
CMD_WRITE = 0,
|
CMD_WRITE = 0,
|
||||||
};
|
};
|
||||||
@@ -610,9 +614,22 @@ enum PinCmd_ {
|
|||||||
/** Handle a request message */
|
/** Handle a request message */
|
||||||
static error_t UUSART_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, PayloadParser *pp)
|
static error_t UUSART_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, PayloadParser *pp)
|
||||||
{
|
{
|
||||||
|
struct priv *priv = unit->data;
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case CMD_WRITE:
|
case CMD_WRITE:
|
||||||
return E_NOT_IMPLEMENTED;
|
dbg("Tx req. CR1 0x%p, CR2 0x%p, CR3 0x%p, BRR 0x%p",
|
||||||
|
(void*)priv->periph->CR1,
|
||||||
|
(void*)priv->periph->CR2,
|
||||||
|
(void*)priv->periph->CR3,
|
||||||
|
(void*)priv->periph->BRR);
|
||||||
|
|
||||||
|
uint32_t len;
|
||||||
|
const uint8_t *pld = pp_tail(pp, &len);
|
||||||
|
|
||||||
|
TRY(sync_send(priv, pld, len));
|
||||||
|
return E_SUCCESS;
|
||||||
|
//return E_NOT_IMPLEMENTED;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return E_UNKNOWN_COMMAND;
|
return E_UNKNOWN_COMMAND;
|
||||||
|
|||||||
Reference in New Issue
Block a user