Moved to static allocated framebuffer and USB vcom rx buffer

This commit is contained in:
Silvano Seva 2020-11-27 22:33:14 +01:00
parent 40e6c0aef9
commit 3bb7e2cfd4
2 changed files with 6 additions and 27 deletions

View File

@ -88,10 +88,10 @@
#define LCD_FSMC_ADDR_DATA 0x60040000 #define LCD_FSMC_ADDR_DATA 0x60040000
/* /*
* LCD framebuffer, allocated on the heap by display_init(). * LCD framebuffer, statically allocated.
* Pixel format is RGB565, 16 bit per pixel * Pixel format is RGB565, 16 bit per pixel
*/ */
static uint16_t *frameBuffer; static uint16_t frameBuffer[SCREEN_WIDTH * SCREEN_HEIGHT];
void __attribute__((used)) DMA2_Stream7_IRQHandler() void __attribute__((used)) DMA2_Stream7_IRQHandler()
{ {
@ -113,19 +113,8 @@ static inline __attribute__((__always_inline__)) void writeData(uint8_t val)
void display_init() void display_init()
{ {
/* Framebuffer size, in bytes */
const size_t fbSize = SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(uint16_t);
/* Allocate framebuffer, two bytes per pixel */
frameBuffer = (uint16_t *) malloc(fbSize);
if(frameBuffer == NULL)
{
printf("*** LCD ERROR: cannot allocate framebuffer! ***");
return;
}
/* Clear framebuffer, setting all pixels to 0xFFFF makes the screen white */ /* Clear framebuffer, setting all pixels to 0xFFFF makes the screen white */
memset(frameBuffer, 0xFF, fbSize); memset(frameBuffer, 0xFF, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(uint16_t));
/* /*
* Turn on DMA2 and configure its interrupt. DMA is used to transfer the * Turn on DMA2 and configure its interrupt. DMA is used to transfer the
@ -335,11 +324,6 @@ void display_terminate()
/* Shut off FSMC and deallocate framebuffer */ /* Shut off FSMC and deallocate framebuffer */
RCC->AHB3ENR &= ~RCC_AHB3ENR_FSMCEN; RCC->AHB3ENR &= ~RCC_AHB3ENR_FSMCEN;
__DSB(); __DSB();
if(frameBuffer != NULL)
{
free(frameBuffer);
}
} }
void display_renderRows(uint8_t startRow, uint8_t endRow) void display_renderRows(uint8_t startRow, uint8_t endRow)

View File

@ -39,11 +39,12 @@ static __IO uint32_t usbd_cdc_AltSet = 0;
uint8_t outEnpBuffer[CDC_DATA_OUT_PACKET_SIZE]; uint8_t outEnpBuffer[CDC_DATA_OUT_PACKET_SIZE];
/* Circular buffer for incoming data enqueuement: each packet coming from host /* Circular buffer for incoming data enqueuement: each packet coming from host
* is stored here, eventually erasing oldest data * is stored here, eventually erasing oldest data.
* Buffer is statically allocated.
*/ */
struct rb struct rb
{ {
uint8_t *data; uint8_t data[RX_RING_BUF_SIZE];
size_t readPtr; size_t readPtr;
size_t writePtr; size_t writePtr;
} }
@ -203,9 +204,6 @@ int vcom_init()
rxRingBuf.readPtr = 0; rxRingBuf.readPtr = 0;
rxRingBuf.writePtr = 0; rxRingBuf.writePtr = 0;
rxRingBuf.data = (uint8_t *) malloc(RX_RING_BUF_SIZE);
if(rxRingBuf.data == NULL) return -1;
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb,
&USR_cb); &USR_cb);
@ -277,9 +275,6 @@ static uint8_t usbd_cdc_DeInit (void *pdev, uint8_t cfgidx)
/* Open Command IN EP */ /* Open Command IN EP */
DCD_EP_Close(pdev,CDC_CMD_EP); DCD_EP_Close(pdev,CDC_CMD_EP);
/* Deallocate RX buffer */
if(rxRingBuf.data != NULL) free(rxRingBuf.data);
return USBD_OK; return USBD_OK;
} }