Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/FSMCIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#define STM32F412Zx
#endif

#ifdef STM32F412Zx

#include "FSMCIO.h"
#include "dma.h"

Expand Down Expand Up @@ -135,3 +137,5 @@ void FSMCIO::startSend(const void *txBuffer, uint32_t txSize, PVoidCallback done
}

} // namespace codal

#endif
4 changes: 3 additions & 1 deletion src/STMLowLevelTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ void timer_irq_handler(uint8_t index)
__HAL_TIM_CLEAR_IT(timHandle, TIM_IT_CC4);
}

instances[index]->timer_pointer(channel_bitmsk);
if (instances[index]->timer_pointer)
instances[index]->timer_pointer(channel_bitmsk);
}

extern "C" void TIM1_IRQHandler()
Expand Down Expand Up @@ -70,6 +71,7 @@ STMLowLevelTimer::STMLowLevelTimer(TIM_TypeDef* timer, uint8_t irqn) : LowLevelT
this->timer_instance = timer;
this->irqN = irqn;
memset(&TimHandle, 0, sizeof(TIM_HandleTypeDef));
disableIRQ();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove


disableIRQ(); // otherwise it might hit us while we're initializing

Expand Down
24 changes: 20 additions & 4 deletions src/USB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void usb_configure(uint8_t numEndpoints)

#ifdef USB
__HAL_RCC_USB_CLK_ENABLE();
irqn = USB_IRQn;
irqn = USB_HP_CAN1_TX_IRQn;
pcd.Init.speed = PCD_SPEED_FULL;
#else /* USB_OTG_FS */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
Expand All @@ -112,8 +112,14 @@ void usb_configure(uint8_t numEndpoints)
HAL_PCDEx_SetTxFiFo(&pcd, i, FIFO_EP_WORDS);
#endif /* USB */

// USB_HP_CAN1_TX_IRQn
// USB_LP_CAN1_RX_IRQn

NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 5);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix indent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and ifdef

NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
NVIC_SetPriority(irqn, 5);
NVIC_EnableIRQ(irqn);

}

#if 0
Expand Down Expand Up @@ -150,6 +156,8 @@ static UsbEndpointOut *findOutEp(int ep)

extern "C"
{
void USB_LP_IRQHandler(void) { HAL_PCD_IRQHandler(&pcd); }
void USB_HP_IRQHandler(void) { HAL_PCD_IRQHandler(&pcd); }

void OTG_FS_IRQHandler(void) { HAL_PCD_IRQHandler(&pcd); }

Expand Down Expand Up @@ -337,25 +345,33 @@ static void writeEP(uint8_t *data, uint8_t ep, int len)
{
usb_assert(len <= USB_MAX_PKT_SIZE);
uint32_t len32b = (len + 3) / 4;

#ifndef USB
DBG("%d write space: %d words", (int)codal::system_timer_current_time_us(),
USBx_INEP(ep)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV);

while ((USBx_INEP(ep)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) < len32b)
;

DBG("write: %p len=%d at IN %d", data, len, ep);
DBG("write: %p len=%d at IN %d", data, len, ep);
CHK(HAL_PCD_EP_Transmit(&pcd, ep | 0x80, data, len));

if (len)
CHK(USB_WritePacket(pcd.Instance, data, ep, len, 0));
#else
DBG("write: %p len=%d at IN %d", data, len, ep);
CHK(HAL_PCD_EP_Transmit(&pcd, ep | 0x80, data, len));

if (len)
CHK(USB_WritePacket(pcd.Instance, data, ep, len));
#endif

#ifndef USB
USBx_DEVICE->DIEPEMPMSK &= ~0x1U << ep;

while (!(USB_ReadDevInEPInterrupt(pcd.Instance, ep) & USB_OTG_DIEPINT_XFRC))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check usb works overall

;
CLEAR_IN_EP_INTR(ep, USB_OTG_DIEPINT_XFRC);

#endif
DBG("%d write done, ctl=%p", (int)codal::system_timer_current_time_us(),
USBx_OUTEP(0)->DOEPCTL);

Expand Down
20 changes: 18 additions & 2 deletions src/ZSingleWireSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static ZSingleWireSerial *instances[4];

static int enable_clock(uint32_t instance)
{
DMESG("CLK EN");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove

switch (instance)
{
case USART1_BASE:
Expand All @@ -42,6 +43,11 @@ static int enable_clock(uint32_t instance)
NVIC_SetPriority(USART2_IRQn, 2);
NVIC_EnableIRQ(USART2_IRQn);
return HAL_RCC_GetPCLK1Freq();
case USART3_BASE:
__HAL_RCC_USART3_CLK_ENABLE();
DMESG("PCLK1 %d", HAL_RCC_GetPCLK1Freq());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove dmesg

NVIC_EnableIRQ(USART3_IRQn);
return HAL_RCC_GetPCLK1Freq();
#ifdef USART6_BASE
case USART6_BASE:
__HAL_RCC_USART6_CLK_ENABLE();
Expand Down Expand Up @@ -116,6 +122,7 @@ extern "C" void HAL_UART_ErrorCallback(UART_HandleTypeDef *hspi)

DEFIRQ(USART1_IRQHandler, USART1_BASE)
DEFIRQ(USART2_IRQHandler, USART2_BASE)
DEFIRQ(USART3_IRQHandler, USART3_BASE)
#ifdef USART6_BASE
DEFIRQ(USART6_IRQHandler, USART6_BASE)
#endif
Expand Down Expand Up @@ -197,8 +204,9 @@ int ZSingleWireSerial::configureTx(int enable)
if (enable && !(status & TX_CONFIGURED))
{
uint8_t pin = (uint8_t)p.name;
pin_mode(pin, PullNone);
// pin_mode(pin, PullNone);
pin_function(pin, pinmap_function(pin, PinMap_UART_TX));
pin_mode(pin,PullUp);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check this pin mode business

uart.Init.Mode = UART_MODE_TX;
HAL_HalfDuplex_Init(&uart);
status |= TX_CONFIGURED;
Expand Down Expand Up @@ -291,6 +299,7 @@ int ZSingleWireSerial::sendDMA(uint8_t* data, int len)
this->bufLen = len;

int res = HAL_UART_Transmit_DMA(&uart, data, len);
DMESG("TXDMA RES %d ",res);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove


CODAL_ASSERT(res == HAL_OK, DEVICE_HARDWARE_CONFIGURATION_ERROR);

Expand Down Expand Up @@ -326,16 +335,23 @@ int ZSingleWireSerial::getBytesReceived()
{
if (!(status & RX_CONFIGURED))
return DEVICE_INVALID_PARAMETER;

#ifdef STM32F1
return hdma_rx.Instance->CNDTR;
#else
return hdma_rx.Instance->NDTR;
#endif
}

int ZSingleWireSerial::getBytesTransmitted()
{
if (!(status & TX_CONFIGURED))
return DEVICE_INVALID_PARAMETER;

#ifdef STM32F1
return hdma_tx.Instance->CNDTR;
#else
return hdma_tx.Instance->NDTR;
#endif
}

int ZSingleWireSerial::sendBreak()
Expand Down
4 changes: 4 additions & 0 deletions src/codal_target_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ int target_random(int max)
device and in any context. These bits can never be altered by the user.
The 96-bit unique device identifier can also be read in single bytes/half-words/words in different ways and then be concatenated using a custom algorithm.
*/
#ifdef STM32F1
#define STM32_UUID ((uint32_t *)0x1FFFF7E8)
#else
#define STM32_UUID ((uint32_t *)0x1FFF7A10)
#endif
uint64_t target_get_serial()
{
// uuid[1] is the wafer number plus the lot number, need to check the uniqueness of this...
Expand Down
38 changes: 33 additions & 5 deletions src/dma_f1.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "dma.h"
#include "CodalDmesg.h"
#include "ErrorNo.h"

#ifdef STM32F1

#include "stm32f1xx.h"
#define NUM_STREAMS 7
#define NUM_DMA 2

Expand Down Expand Up @@ -61,7 +62,7 @@ MBED_WEAK const DmaMap TheDmaMap[] = //
{UART4_BASE, DMA_RX, 13},
{UART4_BASE, DMA_TX, 15},
{DAC_BASE, DMA_TX, 13},
#endif
#endif

// The end
{0, 0, 0}};
Expand All @@ -71,7 +72,6 @@ static DMA_HandleTypeDef *handles[7 + 5];
#define HANDLE_IDX(id) (id < 10 ? id - 1 : id - 4)
static void irq_callback(int id)
{
LOG("DMA irq %d", id);
id = HANDLE_IDX(id);
if (handles[id])
HAL_DMA_IRQHandler(handles[id]);
Expand All @@ -97,6 +97,23 @@ void DMA2_Channel4_5_IRQHandler()
irq_callback(15);
}

int lookup_dma(uint32_t peripheral, uint8_t rxdx)
{
int id = -1;
const DmaMap *map;

for (map = TheDmaMap; map->peripheral; map++)
{
if (map->peripheral == peripheral && map->rxdx == rxdx)
{
id = HANDLE_IDX(map->channel);
break;
}
}

return id;
}

int dma_init(uint32_t peripheral, uint8_t rxdx, DMA_HandleTypeDef *obj, int flags)
{
memset(obj, 0, sizeof(*obj));
Expand All @@ -117,7 +134,7 @@ int dma_init(uint32_t peripheral, uint8_t rxdx, DMA_HandleTypeDef *obj, int flag
}
}

CODAL_ASSERT(map->peripheral);
CODAL_ASSERT(map->peripheral, DEVICE_HARDWARE_CONFIGURATION_ERROR);

obj->Instance = streams[id].instance;

Expand Down Expand Up @@ -150,7 +167,7 @@ int dma_init(uint32_t peripheral, uint8_t rxdx, DMA_HandleTypeDef *obj, int flag
#endif

int res = HAL_DMA_Init(obj);
CODAL_ASSERT(res == HAL_OK);
CODAL_ASSERT(res == HAL_OK, DEVICE_HARDWARE_CONFIGURATION_ERROR);

LOG("DMA init %p irq=%d ch=%d str=%d", obj->Instance, streams[id].irqn, map->channel,
map->stream);
Expand All @@ -160,4 +177,15 @@ int dma_init(uint32_t peripheral, uint8_t rxdx, DMA_HandleTypeDef *obj, int flag
return 0;
}

void dma_set_irq_priority(uint32_t peripheral, uint8_t rxdx, int priority)
{
int id = lookup_dma(peripheral, rxdx);

CODAL_ASSERT(id != -1, DEVICE_HARDWARE_CONFIGURATION_ERROR);

NVIC_DisableIRQ(streams[id].irqn);
NVIC_SetPriority(streams[id].irqn, priority);
NVIC_EnableIRQ(streams[id].irqn);
}

#endif
1 change: 1 addition & 0 deletions src/pinmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "pinmap.h"
//#include "PortNames.h"
#include "pin_device.h"
#include "CodalDmesg.h"

#define error MBED_ERROR

Expand Down