Skip to content

Instantly share code, notes, and snippets.

@Arachnid
Created December 21, 2013 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arachnid/8069083 to your computer and use it in GitHub Desktop.
Save Arachnid/8069083 to your computer and use it in GitHub Desktop.
Everything you need to bootload with an SCB UART in PSoC 4
void CyBtldrCommStart(void) {
UART_Start();
}
void CyBtldrCommStop (void) {
UART_Stop();
}
void CyBtldrCommReset(void) {
UART_SpiUartClearRxBuffer();
UART_SpiUartClearTxBuffer();
}
cystatus CyBtldrCommWrite(uint8* buffer, uint16 size, uint16* count, uint8 timeOut) {
for(*count = 0; *count < size; (*count)++) {
UART_UartPutChar(buffer[*count]);
}
return CYRET_SUCCESS;
}
cystatus CyBtldrCommRead (uint8* buffer, uint16 size, uint16* count, uint8 timeOut) {
int timeoutUs = timeOut * 10000;
cystatus status = CYRET_TIMEOUT;
*count = 0;
while(*count < size && timeoutUs >= 0) {
if(UART_SpiUartGetRxBufferSize() > 0) {
buffer[(*count)++] = UART_UartGetByte();
// Switch to byte-to-byte timeout and mark as success
timeoutUs = 10000; //10mS
status = CYRET_SUCCESS;
} else {
CyDelayUs(10);
timeoutUs -= 10;
}
}
return status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment