hi i am using nucleol073rz board , trying the IAP xmodem usart example , not able to load bin file more than 15KB cant find the problem or understand why ? whereas for code less than 15KB it is working.
Below is the code snippets , not able to debug as well i suspect the flash is not able to erase completely need some advice on this .
https://github.com/ferenc-nemeth/stm32-bootloader
//////////////////////////////////flash operation////////////////////////////////////////////
flash_status flash_erase(uint32_t address)
{
HAL_FLASH_Unlock();
flash_status status = FLASH_ERROR;
FLASH_EraseInitTypeDef erase_init;
uint32_t error = 0u;
erase_init.TypeErase = FLASH_TYPEERASE_PAGES;
erase_init.PageAddress = address;
/* Calculate the number of pages from "address" and the end of flash. */
erase_init.NbPages = ((FLASH_APP_END_ADDRESS - address) / FLASH_PAGE_SIZE);
/* Do the actual erasing. */
if (HAL_OK == HAL_FLASHEx_Erase(&erase_init, &error))
{
status = FLASH_OK;
}
HAL_FLASH_Lock();
return status;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
flash_status flash_write(uint32_t address, uint32_t *data, uint32_t length)
{
flash_status status = FLASH_OK;
HAL_FLASH_Unlock();
/* Loop through the array. */
for (uint32_t i = 0u; (i < length) && (FLASH_OK == status); i++)
{
/* If we reached the end of the memory, then report an error and don't do anything else.*/
if (FLASH_APP_END_ADDRESS <= address)
{
status |= FLASH_ERROR_SIZE;
}
else
{
/* The actual flashing. If there is an error, then report it. */
if (HAL_OK != HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data[i]))
{
status |= FLASH_ERROR_WRITE;
}
/* Read back the content of the memory. If it is wrong, then report an error. */
if (((data[i])) != (*(volatile uint32_t*)address))
{
status |= FLASH_ERROR_READBACK;
}
/* Shift the address by a word. */
address += 4u;
}
}
HAL_FLASH_Lock();
return status;
}
////////////////////////////////////////////////////////////////////////////////////
#define FLASH_APP_START_ADDRESS ((uint32_t)0x08008000u)
#define FLASH_APP_END_ADDRESS ((uint32_t)0x08030000u)
//////////////////////////////////////////////////////////////////////////////////
void xmodem_receive(void)
{
volatile xmodem_status status = X_OK;
uint8_t error_number = 0u;
x_first_packet_received = false;
xmodem_packet_number = 1u;
xmodem_actual_flash_address = FLASH_APP_START_ADDRESS;
/* Loop until there isn't any error (or until we jump to the user application). */
while (X_OK == status)
{
uint8_t header = 0x00u;
/* Get the header from UART. */
uart_status comm_status = uart_receive(&header, 1u);
/* Spam the host (until we receive something) with ACSII "C", to notify it, we want to use CRC-16. */
if ((UART_OK != comm_status) && (false == x_first_packet_received))
{
(void)uart_transmit_ch(X_C);
}
/* Uart timeout or any other errors. */
else if ((UART_OK != comm_status) && (true == x_first_packet_received))
{
status = xmodem_error_handler(&error_number, X_MAX_ERRORS);
}
else
{
/* Do nothing. */
}
/* The header can be: SOH, STX, EOT and CAN. */
switch(header)
{
xmodem_status packet_status = X_ERROR;
/* 128 or 1024 bytes of data. */
case X_SOH:
case X_STX:
/* If the handling was successful, then send an ACK. */
packet_status = xmodem_handle_packet(header);
if (X_OK == packet_status)
{
(void)uart_transmit_ch(X_ACK);
}
/* If the error was flash related, then immediately set the error counter to max (graceful abort). */
else if (X_ERROR_FLASH == packet_status)
{
error_number = X_MAX_ERRORS;
status = xmodem_error_handler(&error_number, X_MAX_ERRORS);
}
/* Error while processing the packet, either send a NAK or do graceful abort. */
else
{
status = xmodem_error_handler(&error_number, X_MAX_ERRORS);
}
break;
/* End of Transmission. */
case X_EOT:
/* ACK, feedback to user (as a text), then jump to user application. */
(void)uart_transmit_ch(X_ACK);
(void)uart_transmit_str((uint8_t*)"\n\rFirmware updated!\n\r");
(void)uart_transmit_str((uint8_t*)"Jumping to user application...\n\r");
flash_jump_to_app();
break;
/* Abort from host. */
case X_CAN:
status = X_ERROR;
break;
default:
/* Wrong header. */
if (UART_OK == comm_status)
{
status = xmodem_error_handler(&error_number, X_MAX_ERRORS);
}
break;
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////
please let me know how to remove the 15kB limit.Thanks in advance.
