Skip to content

Commit

Permalink
- Changed the baud rate to 19.2k
Browse files Browse the repository at this point in the history
- The byte acknowledgements are sent as soon as a byte is received instead of sending all of them after a page has been updated
  • Loading branch information
qb-creates committed Mar 5, 2024
1 parent 67588c0 commit 1f8d054
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions bootloader-atmega1284/lib/IOStream/USART.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
* @note - No parity
* @note - Asynchronous operation
*
* @attention A clock frequency of 18.432MHz and baud rate of 115.2kbs were used during the development of this bootloader.
* @attention A clock frequency of 18.432MHz and baud rate of 19.2kbs were used during the development of this bootloader.
* Update F_CPU and the value in the UBRRn register to get the desired baud rate.
*
*/
void enableUSART(void)
{
UBRR0L = 9;
UBRR0L = 59;
UCSR0B = _BV(RXEN0) | _BV(TXEN0);
UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
}
Expand Down
7 changes: 0 additions & 7 deletions bootloader-atmega1284/lib/Utilities/BootloadUtility.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const uint8_t uploadeFailedCode = 'w';

// Command Responses
const uint8_t pageAck[] = {'P', 'a', 'g', 'e'};
const uint8_t ack[] = {'\r'};

// Page status
const uint8_t lastPageIndicator = 0xFE;
Expand Down Expand Up @@ -89,12 +88,6 @@ void writePageDataToFlash(uint8_t *buf)
boot_spm_busy_wait();
boot_rww_enable();

for (int i = 0; i < 259; ++i)
{
wdt_reset();
usartTransmit(ack, 1);
}

usartTransmit(pageAck, 4);

// Upload is complete if the last byte in the buffer is equal to the lastPageByte.
Expand Down
16 changes: 12 additions & 4 deletions bootloader-atmega1284/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "ButtonUtility.h"
#include "BootloadUtility.h"

const uint8_t ack[] = {'\r'};

int main(void)
{
// Clear watchdog reset flag and disable watchdog timer.
Expand All @@ -23,7 +25,7 @@ int main(void)
// Continue to bootloader section.
enableUSART();
startBootloadIndicator();

while (true)
{
// Check for data in the usart receive buffers.
Expand All @@ -40,8 +42,8 @@ int main(void)
if (dataStruct.data == '\0' && !writeToFlash)
{
bufferCounter = 0;
if (!memcmp(dataBuffer, "RTU", 4))

if (!memcmp(dataBuffer, "RTU", 4))
{
writeToFlash = true;
wdt_enable(WDTO_8S);
Expand All @@ -50,7 +52,13 @@ int main(void)

continue;
}


// The microcontroller is writing to flash. Send a byte acknowledgement back to the server.
if (writeToFlash)
{
usartTransmit(ack, 1);
}

// Check if the data buffer has been completely filled with page data
if (bufferCounter == 259)
{
Expand Down
4 changes: 2 additions & 2 deletions bootloader-atmega128a/lib/IOStream/USART.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
* @note - No parity
* @note - Asynchronous operation
*
* @attention A clock frequency of 7.3728MHz and baud rate of 115.2kbs were used during the development of this bootloader.
* @attention A clock frequency of 7.3728MHz and baud rate of 19.2kbs were used during the development of this bootloader.
* Update F_CPU and the value in the UBRRn register to get the desired baud rate.
*
*/
void enableUSART(void)
{
UBRR1L = 3;
UBRR1L = 23;
UCSR1B = _BV(RXEN1) | _BV(TXEN1);
UCSR1C = _BV(UCSZ11) | _BV(UCSZ10);
}
Expand Down
7 changes: 0 additions & 7 deletions bootloader-atmega128a/lib/Utilities/BootloadUtility.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const uint8_t uploadeFailedCode = 'w';

// Command Responses
const uint8_t pageAck[] = {'P', 'a', 'g', 'e'};
const uint8_t ack[] = {'\r'};

const uint8_t uploadCompleteByte = 0xFE;

Expand Down Expand Up @@ -85,12 +84,6 @@ void writeProgramDataToFlash(uint8_t *buf)
boot_spm_busy_wait();
boot_rww_enable();

// Acknowledge that the 259 bytes of data were received
for (int i = 0; i < 259; ++i)
{
usartTransmit(ack, 1);
}

usartTransmit(pageAck, 4);

// Check page status byte.
Expand Down
8 changes: 8 additions & 0 deletions bootloader-atmega128a/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "BootloadUtility.h"
#include "Timer.h"

const uint8_t ack[] = {'\r'};

int main(void)
{
// Clear watchdog reset flag and disable watchdog timer.
Expand Down Expand Up @@ -70,6 +72,12 @@ int main(void)
continue;
}

// The microcontroller is writing to flash. Send a byte acknowledgement back to the server.
if (writingToFlash)
{
usartTransmit(ack, 1);
}

// Check if the data buffer has been completely filled with page data
if (bufferCounter == 259)
{
Expand Down

0 comments on commit 1f8d054

Please sign in to comment.